crffty
crffty

Reputation: 444

Routing with 'if' statement

I need my site to be behind a login wall. so far I have done this with an "if" statement:

Route::get('/', function() {
    if (Auth::check()) {
        return view('pages.feed');
    } else {
        return view('auth.login');
    }
});

i also need to call the feedController though. how can i add

'feedController@index'

to the statement?

Upvotes: 0

Views: 1002

Answers (1)

Niklesh Raut
Niklesh Raut

Reputation: 34914

Add your condition in controller not in web.php routing

Route::get('/', 'feedController@index');

and in feedController controller

function index(){
    .........
    if (Auth::check()) {
        return view('pages.feed');
    } else {
        return view('auth.login');
    }
}

Also be sure to use use Illuminate\Support\Facades\Auth; or just \ as if (\Auth::check()) {

Upvotes: 1

Related Questions