Laravel 5列出htmlentities()期望参数1为字符串 [英] Laravel 5 lists htmlentities() expects parameter 1 to be string
问题描述
我有以下内容:
\ App \ Models \ Finance \ FinanceAccount :: lists('name','id')
\App\Models\Finance\FinanceAccount::lists('name', 'id')
在我的一种观点的顶部,但它总是给我错误:
At the top of one of my views but it keeps giving me the error:
htmlentities() expects parameter 1 to be string, array given (View: mysite\views\modals\add.blade.php)
我在做什么错了?
这是一个数组,这很有意义,我将其放入一个选择中,它现在可以正常工作:
That makes sense about it being an array, I put it into a select and it's working now:
<div class="form-group">
{!!Form::label('Account')!!}
{!!Form::select('account', \App\Models\Finance\FinanceAccount::getSelectOptions(), 1, ['class' => 'form-control'])!!}
</div>
是否可以为视图设置名称空间,所以我不必一直输入完整的名称空间?
Is there a way to set the namespace for views, so I don't have to type the full namespace all the time?
推荐答案
lists
给出了一个数组,您不能使用{{ }}
回显该数组.您需要做的就是如果要打印其内容,则循环或implode
该数组.
lists
gives an array and that's not something you can echo out with {{ }}
. What you need to do is to loop or implode
the array if you want to print it's content.
使用foreach
@foreach ($list as $item)
{{ $item }}<br />
@endforeach
使用 implode
{{ implode(', ', $list) }}
使用Form::select
{!! Form::select('foo', $list) !!}
If you don't want to use your namespace (which you never should) in your view, send the data from your controller to your view file.
如果您的控制器中有此
public function foo() {
$baz = \App\Models\Finance\FinanceAccount::getSelectOptions();
return view('bar', compact('baz'));
}
$baz
变量随即在您的视图文件中可用.因此,您可以执行以下操作:
The $baz
variable is then available in your view file. So you can do this:
{!! Form::select('foo', $baz) !!}
这篇关于Laravel 5列出htmlentities()期望参数1为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!