Support the ongoing development of Laravel.io →
Eloquent Views
Last updated 2 years ago.
0

Your accessor is called but you misunderstand how it works (in the docs there's a mistake in the example, that's true).

It doesn't take any argument, so $value is null thus your method always evaluates to the 2nd return.

This is what you want:

public function getStatusAttribute() 
{
    return ($this->attributes['status'] == 1) ? 'Bestätigt' : 'Wartend';
}
Last updated 2 years ago.
0

Thank you for you answer.

Maybe it is a point for an update for the documentation.

I get the query results with an querybuilder instance. Is the Accessor only called when i'm using the Eloquent ORM?

Last updated 2 years ago.
0

You can make a pull request to the docs. Anyway show the current code with calling this attribute, since the problem is somewhere else for sure.

Last updated 2 years ago.
0

Ok. I find the solution. I try to call the Accessor over the DB::Table('Reservations'). The is not working. You have to use the Modelclass....

Last updated 2 years ago.
0

felixgerdes said:

Ok. I find the solution. I try to call the Accessor over the DB::Table('Reservations'). The is not working. You have to use the Modelclass....

Accessors are a feature of the Eloquent ORM - so yes, you do need to use the model. DB::Table access the table directly using the query builder - it doesn't have access to models.

Last updated 2 years ago.
0

Thank´s for helping..

Last updated 2 years ago.
0

if you are using query builder you can use hydrate method of eloquent to convert to an eloquent instance.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.