Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@yield, @section in Laravel

Hello everyone I want to load shopReq.blade.php file in master.blade.php and I am successful in doing this. But when I load modals.blade.php file in shopReq.blade.php it does not included. Am I doing something wrong here? Please help.

master.blade.php (in views/layouts):

<html>
   <body >
          @yield('content')
    </body>
</html>

shopReq.blade.php (in views)

@extends('layouts.master')
@section('content')
<h1>Hello I am in shopReq.blade.php
@yield(content)
@endsection

modals.blade.php (in views)

@extends('shopReq')
@section('content')
<h1>Hello I am in modals.blade.php
@endsection

web.php:

Route::group(['middleware' =>['web']], function()
    {
    Route::get('/', function () {
        return view('welcome');
    })->name('home');
});
like image 450
Knowledge Seeker Avatar asked Nov 21 '25 01:11

Knowledge Seeker


2 Answers

replace @yield(content) on shopReq.blade.php with @include('modals')

modals.blade.php

<h1>Hello I am in modals.blade.php</h1>

on routes

return view('shopReq');
like image 86
bhill77 Avatar answered Nov 22 '25 15:11

bhill77


As the user milo526 has said.

You have @yield('content') twice.

For any blade directive (yield, section, component...)

if there is a same name inside brackets it will be overwritten.

And now I have spot that you don't have the quotes ' ' on your second yield:

@yield(content)
like image 40
lewis4u Avatar answered Nov 22 '25 16:11

lewis4u



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!