Laravel 5.2 conditional extends template in Blade

Viewed 4004

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.

2 Answers

Try this code, parenterais are important

@extends(Auth::user()->rol_id == 1 ? 'layouts.admin' : ((Auth::user()->rol_id == 2) ? 'layouts.client' : 'layouts.client'))
Related