I want to extend template based on condition. I know i can use @if @else
statement in blade. I am doing the same thing, but blade extending both the template. I don't know why.
@if(isset(Auth::user()->id))
@extends('layouts.adminlayout')
@else
@extends('layouts.default')
@endif
@section('content')
i am the home page
{{ isset(Auth::user()->id) }}
@stop
As, you can see i am checking whether or not user login-ed and then extend the template layout. But it is extending from both the layout.
Please help me.
The first line in your extended blade view must be the @extends
directive.
Try using a ternary operator for this.
@extends(isset(Auth::user()->id) ? 'layouts.adminlayout' : 'layouts.default');
UPDATE for role based layouts. Refer to this question for more conditions.
@extends((!isset(Auth::user()->id))? 'layouts.default': ((Auth::user()->role == 'admin') ? 'layouts.adminlayout' : 'layouts.moderatorlayout'));
Try this code, parenterais are important
@extends(Auth::user()->rol_id == 1 ? 'layouts.admin' : ((Auth::user()->rol_id == 2) ? 'layouts.client' : 'layouts.client'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With