Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer View is not loading variable into view

I created 3 composer views previously and they all work properly, but then I created another one, which doesn't seem to work. I've been trying to get it to work, it doesn't seem to be something related to my code. I will drop a piece of it here, but I still don't think it's the 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 than I included the provider inside app.php

App\Providers\EvenComposerProvider::class

When I try to loop through $evens with the foreach, it throws the error:

Undefined variable: evens

My rough guess will be that, Laravel does not compile app.php

like image 959
Agil Avatar asked Feb 15 '18 19:02

Agil


1 Answers

So here is the solutions which might work for people in same sitatuin. First try these commands:

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

I tried a few of them than deleted bootstrap/cache/config file and it worked.

like image 130
Agil Avatar answered Oct 19 '22 23:10

Agil