Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save epicsagas/8c4eca6af3968d06a325bf47c134c404 to your computer and use it in GitHub Desktop.
Save epicsagas/8c4eca6af3968d06a325bf47c134c404 to your computer and use it in GitHub Desktop.
[Laravel] Use accessor with same field name.
<?php
namespace App\\Models;
use Eloquent;
class Post extends Eloquent
{
protected $appends = [
'thumbnail',
];
// Will raise "Undefined index:" exception without below hidden original attribute.
protected $hidden = [
'thumbnail',
];
pubilc function getThumbnailAttribute()
{
return $this->attributes['thumbnail'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment