Answer the question
In order to leave comments, you need to log in
What options for the logic of end-to-end information in the section can you recommend?
There is a sidebar. How to transfer information to it? Which is visible on any page. In it, for example, the last comment, or the last announcement, or something else (from different database tables)
How is it better to do this? At the moment the logic is not clear. For a separate page, it’s clear, through a router and a controller. But how to implement for a pass-through block?
Answer the question
In order to leave comments, you need to log in
I can suggest using the so-called composers. Create a View/Composers folder in the app folder, create a class/file in the Composers folder, let's call it AddStatistic.php:
namespace App\View\Composers;
use App\Comment;
use App\Blog;
use Illuminate\View\View;
class AddStatistic
{
public function compose(View $view)
{
$statistic = [
'last_comments' => Comment::getLast(),
'top_rated' => Blog::topRated(),
];
$view->with('statistic', $statistic);
}
}
namespace App\Providers;
use App\View\Composers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
...
$this->app['view']->composer(['partials.statistic'], Composers\AddStatistic::class);
}
...
}
view composer. Read about him. Make it like a widget.
Oops... Didn't notice you already answered
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question