Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save epicsagas/8c4eca6af3968d06a325bf47c134c404 to your computer and use it in GitHub Desktop.

Select an option

Save epicsagas/8c4eca6af3968d06a325bf47c134c404 to your computer and use it in GitHub Desktop.

Revisions

  1. epicsagas created this gist Jun 24, 2021.
    22 changes: 22 additions & 0 deletions laravel-use-accessor-with-same-fieldname.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?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'];
    }
    }