Luiz Wynne
Luiz Wynne

Reputation: 500

Laravel Eloquent query - Could not convert to int

I am trying to make build a query on Eloquent using pluck, but for some reason, the return message given to me is:

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) 

Can someone give me a clue on what is happening?

controller method:

$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');

My view seems to be normal:

<div class="form-group">
                                    <div class="col-md-6">
                                        {!! Form::select('user_id',[''=>'Chose user'] + $users,null,['class'=>'form-control']) !!}
                                    </div>
                                </div>

Upvotes: 3

Views: 1226

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

You're trying to concatinate a collection and an array. So, change this:

[''=>'Chose user'] + $users

To:

[''=>'Chose user'] + $users->toArray()

Upvotes: 3

Related Questions