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

Randy_Johnson's avatar

What is the difference between @section and @include.

I am currently trying to get @section to work and not succeeding. I have a file in my layouts called "dashboard.blade.php" but when I call it nothing appears.

@section('layout.dashboard') @yield

It just throws an error. But the documentation is saying that this is what needs to show the dashboard layout.

Please help.

0 likes
5 replies
tykus's avatar

You typically would @extend the layout, and in the layout template you would @yield the contents of the @section that is defined in the child template, e.g.

// layout.dashboard
@yield('content')
// child template
@section('content')
 // markup
@endsection

The 'content' section name connects to the yield placeholder in the layout

Randy_Johnson's avatar

But I want the dashboard only to be seen by an admin and not by a user. With the laravel auth system, would not the user also see this dashboard.

Snapey's avatar

You have to think of it in terms of child and parent, but opposite to what you would do with includes.

You might think of starting with a 'parent' view and then including sub-views

Most blade templates are the other way around.

You start with the child and then extend to the parent. So, the parent is processed, and when it encounters a yield it reverts control back to a named section in the child

Please format your code by putting 3 backticks ``` on a line before and after each code block if you want better help

tykus's avatar

I don't know how to answer this... because it is not really related to the original question.

Route-level protection

The users who are authorized to visit URLs in your application is not defined at the View level, you would use the auth middleware to protect those routes. Similarly, you can use the can middleware (along with the associated gates and policies) to protect some routes from authenticated, but unauthorized users

View-level protection

Within a view template, you can conditionally render different parts of your view depending on a user being authenticated using the @auth or @guest directives as appropriate to your situation

@auth
	// only visible to authenticated users
@endauth
@guest
	// only visible to 
@endguest

Similarly, whenever you have different permissions for authenticated users, you can use the @can directive to conditionally render parts of the view depending on the authenticated user being authorized.

Please or to participate in this conversation.