6

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

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

By the way, this goes for anything does not work properly with Providers the reason to that is, because Laravel does not compile, clear cache and stuff, each time you run the website. Due to performance it uses old setting.
0

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

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

4 Comments

By the way I tried the other one and it worked in 3 other composer but not working with this one
Can you please vote-up? I might get better chance to have it solved that way
Ive voted, give us the code for your other composer thats working
Thanks, it is completely same as it's given for the Even Composer. I literally copied and pasted and than changed unique names. That is why I don't understand why it doesn't work. I tried to do DD($evens) and my provider seem to not even call my composer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.