Home:ALL Converter>Laravel Blade Passing Variables to Other Blades

Laravel Blade Passing Variables to Other Blades

Ask Time:2018-03-15T06:58:20         Author:LucyTurtle

Json Formatter

I have tried a few things to try to get this to work. I was looking at this -- Laravel Blade - pass variable via an @include or @yield -- question about how to pass variables between blades but I can't seem to get it to work!

I have a view calling my header view (in /resources/views/layouts/frontendbasic.blade.php):

@include('common/head', array('url'=>'www.url.com'))

And in the header blade (in /resources/views/common/head.blade.php) I am calling that variable like this:

<meta property="og:url" content="{{ $url }}" />

And I get the error:

Undefined variable: url
(View: ...\resources\views\common\head.blade.php) 
(View: ...\resources\views\common\head.blade.php) 
(View: ...\resources\views\common\head.blade.php)

I am wondering what I am doing wrong?

Author:LucyTurtle,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49288954/laravel-blade-passing-variables-to-other-blades
Caio Kawasaki :

The correct thing is to pass a variable through the controller:\n\nreturn view('view.path', [\n 'url' => 'www.url.com'\n]);\n\n\nhowever, try as below:\n\n@include('common.head', ['url' => 'www.url.com'])\n",
2018-03-14T23:28:52
yy