My parent view looks like this:
show.blade.php
@include('inquiries.partials.inquiries')
It uses the following partial:
inquiries.blade.php
<ul>
@foreach($inquiry as $key => $item)
<li>
@include('inquiries.partials.inquiry')
</li>
@endforeach
</ul>
Which uses another partial:
inquiry.blade.php
<div class="row">
<div class="col-xs-10">
<div class="data"> ... </div>
</div>
<div class="col-xs-2 text-right">
@yield('inquiry.toolbar', '')
</div>
</div>
In show.blade.php I want to define inquiry.toolbar section for inquiry.blade.php, however I need to access $key variable from inquiries.blade.php file, like so:
@include('inquiries.partials.inquiries')
@section('inquiry.toolbar')
{!! button_delete([
'route' => ['inquiries.items.destroy', $key]
]) !!}
@stop
However, the code above does not work (I get "Undefined variable: key").
Is it possible?
You can pass data when including a view, like so:
<ul>
@foreach($inquiry as $key => $item)
<li>
@include('inquiries.partials.inquiry', compact('key'))
</li>
@endforeach
</ul>
And it will be available on your view.
Check the docs for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With