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';
}
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?
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.
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....
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.
if you are using query builder you can use hydrate method of eloquent to convert to an eloquent instance.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community