how to get display pluck column from a model function in blade file

Posted 1 week ago by princeoo7

I am stuck with a pretty simple and stupid problem :/

i have a function in model which fetch the name and color code related to status from db called status().

code:

public function status()
    {
        return $this->hasOne(Status::class, 'code', 'status')->pluck('name', 'color');
    }

i am using it in blade like this, as of now to see the result:

$category->status()

output is like this:

{"green":"Active"}

if i do,

$category->status()->name

i get error :

Property [name] does not exist on this collection instance.     

where am i going wrong with pluck as you can see that instead of giving me a name based keyword in result it is only fetching the value of the key.

i hope someone can help me out this is one ...

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