how send data between child and master blade

Viewed 227

how send data between child and master blade ?

*master.blade.php*

@if($sidebar == 'true')
<div>...</div>
@endif

*index.blade.php*
@extends('master')
@section('sidebar','true')

please help me. do not use Route and controller and ...

1 Answers

To pass a variable from the child to the parent, the parent must first specify that it expects a variable. This is done using the yield keyword

master.blade.php

@if(@yield('hasSidebar') == '1')
<div>...</div>
@endif

index.blade.php

<?php

  @extends('master')

  @section('hasSidebar', '1')
Related