yagrasdemonde
2 months ago
304
5
Laravel

Pluck with column JSON

Posted 2 months ago by yagrasdemonde

Hello,

I'm looking for to pluck query with a JSON column, but I don't know how to do.

So I have in my user table a column custom_properties

Inside this, I have the key name_enterprise

{
  "name_enterprise": "Enterprise 1"
}

I want to build a dropdown with this field.

So for a standard field I do

$users = User::pluck('firstname', 'id')->toArray();

Output => 
array(
6 => "John"
7 => "Mike"
81 => "Nate"
)

How can I do to get my name_enterprise key of Json column ?

Thank you very much

PS : In my User model, I defined and type of column field is set to JSON. I'm using Laravel 7

protected $casts = [
'custom_properties' => 'array'
];

Please sign in or create an account to participate in this conversation.