Mohammad Akhondi
Mohammad Akhondi

Reputation: 35

how send data between child and master blade

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 ...

Upvotes: 2

Views: 627

Answers (1)

Adonai Nangui
Adonai Nangui

Reputation: 571

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')

Upvotes: 1

Related Questions