The accessor is working when you use it through your model. The code below is based on the query builder. Try
$player = Player::where('', '')->firstOrFail();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have problems with date-format in json-output.
In the model i use an accessor
public function getdatumAttribute($value) {
return Carbon::parse($value)->format('d.m.Y');
}
With eloquent this works fine. I've got the correct format of the datefield.
If i use the select:
$player = DB::table('players')->select(DB::raw("*,
....
return $player;
the accessor doesn't work und the output of any date is wrong (for me). Why does the accessor not work with the db-select and how can i format the date in json output?
best regards
Please or to participate in this conversation.