Reputation: 93
I need to select distinct value and push them into an array. After that, i need to verify if a variable is situated into the array.
Controller:
$people = DB::table('checklists')->select('incaricato')->distinct()->get()->toArray();
if (in_array(\Auth::user()->id, $people)) {
$variable = "yes";
}
Error:
Object of class stdClass could not be converted to int
Upvotes: 2
Views: 44
Reputation: 544
Use
DB::table('checklists')->distinct()->pluck('incaricato')->toArray()
Upvotes: 0
Reputation: 93
Solution:
$people= \App\Checklist::distinct()->pluck('incaricato')->toArray();
Upvotes: 0
Reputation: 3543
Try with using id
directly instead of going through user
, like this:
if(in_array(Auth::id(), $people))
If it throws the same error, then dump that and check whats it returning
Upvotes: 1