I was not happy with the default created_at date format in my database table so I decided to create Accessors which will simply change my date format. But I found out that Accessors is not running. I tried to use it on another column but it doesn't change my output. then I use dd($value) so it can stop in accessor but I found out that it didn't. I am getting my data from the database and the accessor is been bypassed.
my accessor in model class is:
public function getCreatedAtAttribute($value)
{
dd($value);
}
But it does not effect anything as I am getting my output of:
$case=Allcase::with('donner')->get();
print_r($case);
and also no effect to created_at:
You can customize the actual attribute value in this way
public function getCreatedAtAttribute()
{
return Carbon::parse($this->attributes['created_at'])->format('Y-m-d');
}
Now, you can get your data and print it. You can show the differences now
$case = Allcase::with('donner')->get();
print_r($case);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.