使用Laravel 5.4,我在刀片模板中使用变量变量($$ var)来访问模型属性。除description属性外,所有属性都有效。以下是一个例子:
模型迁移:
Schema::create('user_roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50);
$table->string('description', 255);
$table->timestamps();
});
控制器:
...
$tableCols = [
['name' => 'id'],
['name' => 'name'],
['name' => 'description']
]
...
刀片不工作:
@foreach($tableCols as $tableCol)
{{ $name = $tableCol['name']}}
<td>{{ $model->$$name }} </td>
@endforeach
错误:未定义的变量:description
刀片工作:
<td> {{ $model->name }} </td>
<td> {{ $model->description }} </td>
如何获取变量variable $$以获取description属性。谢谢!