Laravel Blade Variable Variable
With Laravel 5.4, I am using a variable variable ($$var) in a blade template to access a model attribute. All the attributes work except the description attribute. Below is an example:
Model Migration:
Schema::create('user_roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50);
$table->string('description', 255);
$table->timestamps();
});
Controller:
...
$tableCols = [
['name' => 'id'],
['name' => 'name'],
['name' => 'description']
]
...
Blade NOT WORKING:
@foreach($tableCols as $tableCol)
<td> </td>
@endforeach
Error: Undefined variable: description
Blade WORKING:
<td> </td>
<td> </td>
How do I get my variable variable $$ to get the description attribute. Thanks!
from Laravel Questions and Answers https://laravelquestions.com/php/laravel-blade-variable-variable/
via Lzo Media
No comments:
Post a Comment