2 years ago

Composer View is not loading variable into view

Posted 2 years ago by agilasadi

I have a composer which is called EvenComposer inside that composer I have a function compose in there I try to return a variable $evens

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

And than a Provider which is called EvenComposerProvider is supposed to to call to that composer and load the data into the include view includes.aklinkoses with the code below:

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

I also doublechecked or maybe more, if I Included it inside app.php

and I have the line in there App\Providers\EvenComposerProvider::class,.

Inside the view I have this code:

@foreach($evens as $even)

pretty basic but yet gives the error: Undefined variable: evens

By the way, I have 3 other comopser views which work pretty normal so far. I might miss anything at all, haven't worked with composers for a while. If I didn't mention something than I probably missed it.

Please sign in or create an account to participate in this conversation.