Reputation: 236
I would like to return two variables from my controller function. The purpose of this is to use them both in my index.blade.php form.
public function index()
{
$checkauth=Auth::check();
$postl= PostModell::orderby('created_at','desc')->paginate(4);
return view ('posts.index')->with('postl',$postl);
}
From the above sample code the two variables are $checkauth
and $postl
Upvotes: 2
Views: 1333
Reputation: 163748
You can use this syntax:
return view ('posts.index', compact('postl', 'checkauth'));
Or:
return view ('posts.index', ['postl' => $postl, 'checkauth' => $checkauth]);
But actually you don't need to pass $checkauth
because you can do the check in the view directly with:
@if (auth()->check())
Or even with the @auth
directive:
@auth
{{-- The user is authenticated --}}
@endauth
Upvotes: 5