Boss Pogs
Boss Pogs

Reputation: 137

how to get the value in array from database laravel

I want to extract the values from array in a column from database. For example, my value in my permission column is ["Create","Edit","Delete]. So when I dd($user->permission) it would return like that. How can I get the value from it so that I can return the result in a list. I have really no idea for now and what I cannot find similar question to mine.

Upvotes: 0

Views: 46

Answers (1)

PunyFlash
PunyFlash

Reputation: 1086

This is a task for mutators. Simply add to your model:

protected $casts = [
    'permission' => 'array',
];

Upvotes: 4

Related Questions