Carmine Rub
Carmine Rub

Reputation: 93

Push value in array and verify

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

Answers (3)

Sunny Kumar
Sunny Kumar

Reputation: 544

Use

DB::table('checklists')->distinct()->pluck('incaricato')->toArray() 

Upvotes: 0

Carmine Rub
Carmine Rub

Reputation: 93

Solution:

$people= \App\Checklist::distinct()->pluck('incaricato')->toArray();

Upvotes: 0

Nikola Gavric
Nikola Gavric

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

Related Questions