I have a simple question can we store the value that will be yielded in a variable.
for instance an example
$var = @yield('title')
If no, then is there any way to get the value of this yield
Yes you can retrieve the value of an yield which is defined by a section using something like the following, for example:
// Assumed you've the following in your view: @section('title', 'Some Title')
$title = app()->view->getSections()['title']; // Some Title
Basically, the app()->view->getSections() will return you an associative array of all the sections so, to get a specific section, all you need to get an specific index from the array. From the view, you can access the app using the global $app variable, i.e: $app->view or $app['view'].
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