Composer View does not load a variable into a view

I created 3 compositional views earlier, and they all work fine, but I created another one that doesn't seem to work. I tried to get it to work for 3 days, and this does not seem to be related to my code. I will drop a piece of it here, but I still don't think this is code.

Provider EvenComposerProvider:

public function register(){ $this->composeEven(); } public function composeEven(){ view()->composer('includes.aklinkosesi', 'App\Http\Composers\EvenComposer'); } 

Composer EvenComposer:

 class EvenComposer{ public function compose(View $view){ $view->with('evens', Even::orderBy('id','desc')->paginate(10)); } } 

And how did I app.php provider inside app.php

 App\Providers\EvenComposerProvider::class 

When I try to execute the $evens loop using foreach, it throws an error:

Undefined variable: evens

My gross assumption would be that Laravel is not compiling app.php

+5
source share
2 answers

So, here are solutions that can work for people in the same sitatuin. First try the following commands:

 composer update php artisan config:clear php artisan cache:clear composer dumpautoload php artisan cache:clear 

I tried several of them, than deleted the bootstrap/cache/config file, and it worked.

+4
source

You are doing it wrong, put this code in the boot method inside your provider , and also remove the code from register and delete your composeEven method:

 View::composer( 'layouts.aklinkosesi', 'App\Http\Composers\EvenComposer' ); 
0
source

Source: https://habr.com/ru/post/1275385/