Created
June 24, 2021 02:25
-
-
Save epicsagas/8c4eca6af3968d06a325bf47c134c404 to your computer and use it in GitHub Desktop.
[Laravel] Use accessor with same field name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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