Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent query - Could not convert to int

Tags:

php

laravel

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>
like image 339
Luiz Wynne Avatar asked Dec 07 '25 02:12

Luiz Wynne


1 Answers

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

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

To:

[''=>'Chose user'] + $users->toArray()
like image 169
Alexey Mezenin Avatar answered Dec 08 '25 14:12

Alexey Mezenin