我正在尝试使用pluck在Eloquent上构建一个查询,但出于某种原因,给我的返回消息是:
Object of class Illuminate\Support\Collection could not be converted to int (View: /Applications/MAMP/htdocs/Housing_around/resources/views/admin/tasks/create.blade.php)
有人能给我一些关于发生了什么的线索吗?
控制器方法:
$house = House::findOrFail(Auth::user()->house->id);
$jobs = Job::pluck('name', 'id')->all();
$categories = Category::pluck('name', 'id')->all();
$users = User::where('house_id', $house)->pluck('name', 'id');
我的观点似乎很正常:
<div class="form-group">
<div class="col-md-6">
{!! Form::select('user_id',[''=>'Chose user'] + $users,null,['class'=>'form-control']) !!}
</div>
</div>
答案 0 :(得分:3)
您正在尝试连接集合和数组。所以,改变这个:
[''=>'Chose user'] + $users
要:
[''=>'Chose user'] + $users->toArray()