Laravel: Extending different layouts inside if-els

2019-07-17 03:46发布

问题:

I'm trying to extend different layouts inside if-else statement. Here is my code:

@if(Auth::check())
    @extends('layouts.adminPanel')
@else
    @extends('layouts.home')
@endif

But the view files extending both layouts. No matter user logged in or not!

How can I fix it?

回答1:

Add Extends at the first line

@extends(\Auth::check() ? 'layouts.adminPanel' : 'layouts.home')