I have an array that looks like:
$myArray = array(
'firstRow' => array(
0 => array(
'id' => 1
'title' => 'First Cat.'
),
1 => array(
'id' => 2
'title' => 'Second Cat.'
)
),
'SecondRow' => array(
0 => array(
'id' => 3
'title' => 'Third Cat.'
),
1 => array(
'id' => 4
'title' => 'Fourth Cat.'
)
)
);
This is being passed to my blade template. I can echo out values using raw php like:
<?php echo $myArray['firstRow'][0]['title'] ?>
Which works as expected. However, when I try to do what I thought was exactly the same thing using blade's syntax:
{{ $myArray['firstRow'][0]['title'] }}
I get the error:
Trying to get property of non-object
?
Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.
By default you would use the following syntax {{ $some_variable }} to echo out the content of a specific variable in Blade. By default the {{ }} escapes the HTML tags.
Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes. All views in Laravel are usually built in the blade template. Blade engine is fast in rendering views because it caches the view until they are modified. All the files in resources/views have the extension .
Blade Templating Blade is a simple, yet powerful templating engine provided with Laravel. Unlike controller layouts, Blade is driven by template inheritance and sections. All Blade templates should use the . blade. php extension.
I'm afraid you are suspecting of the wrong line of code, because:
Trying to get property of non-object
Is to something being used not as an array, but as an object:
{{ $myArray->firstRow->get(0)->title }}
So, your error is not exactly in this line.
But can be sure by getting the generated view source code in app/storage/views
.
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