Agil
Agil

Reputation: 396

How to send secondary variable to view with composer

In my composer I pass list of data as :

$evens = Even::all()->paginate(10);
$view->with('evens', $evens);

But now I want to also pass if the post is liked by the user or not with:

$likes = Inspiring::select('even_id')->where('user_id', Auth::user()->id)->get();
$likeArr = array_flatten($likes->toArray());

And than activate a class depending on if user liked the post or not

But when I use with I can only send one collection of data. I wonder how I can san this data as collection or pass it as adding $likeArr into $even

Upvotes: 0

Views: 22

Answers (1)

Mahdi Younesi
Mahdi Younesi

Reputation: 7509

Pass an array

return  $view->with(['evens' => $evens, 'likeArr' => $likeArr]);

Upvotes: 3

Related Questions