I have:
Model
public function getUrlAttribute() {
dd($this->created_at);
}
View
@foreach($item as $item)
{{$item->url}}
...
@endforeach
But it returns null, when in fact every row in my table has a created_at datetime. What is going wrong here?
You have to return the value.
public function getUrlAttribute() {
return $this->created_at;
}
I suspect that for whatever reason the created_at
column was not selected when creating the model. What do you get if you do the following?
dd($item->toArray());
You can also access it more directly skipping
$this->getCreatedAtAttribute()
by doing:
public function getUrlAttribute() {
dd($this->attributes['created_at']);
}