Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dali-rajab's avatar

laravel blade layouts inheritence problem

hello every body ! let's say we have this :

layout.blade.php

@section('sidebar')
    @include('sidebar')
@show

@yield('content')

sidebar.blade.php

{{ Auth::user()->full_name}}

page_for_logged_in.blade.php (for logged in users)

@extend('layout')

// the sidebar is already rendered by inheritence

@section('content')
    some content
@endsection

Until here, every think is good, but for the next page (for not logged in users) :

page_for_not_logged_in.blade.php (for not logged in users)

@extend('layout')

@section('sidebar') // here i'm trying to make it empty by override
@endsection

@section('content')
    some content
@endsection

But that doesn't work ! it is trying to include the sidebar file. :(

Trying to get property of non-object "full_name"

I know i can wrap it like this :

@auth
    {{ Auth::user()->full_name}}
@endauth

But this is not my goal, i'm just searching for a method to implement overridable sections

0 likes
2 replies
MichalOravec's avatar

In layout

@hasSection('sidebar')
    @yield('sidebar')
@else
    @include('sidebar')
@endif

In child where you don't want to have that sidebar

@extend('layout')

@section('sidebar', null)

@section('content')
    some content
@endsection
1 like
dali-rajab's avatar

Thank you @michaloravec , in fact, i had to replace the null by some thing else to work

@extend('layout')

@section('sidebar')
<!-- Empty section. Do not remove this comment please -->
@endsection

@section('content')
    some content
@endsection

Please or to participate in this conversation.