2

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

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

if ( auth()->check()) Welcome {{ Auth::user()->name }} else Welcome please login endif

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.