title: Conditionally append attribute to model in laravel
body: <p>Is it possible to append an attribute to my model whenever a model scope is called?</p>
  
  <p>For example in my controller I want to call a scope to append those dynamic attribute like : </p>
  
  <pre><code>$Media_query = OutDoorMedia::query();
  $Media_query-&gt;orderby('created_at', 'desc');
  $Media_query-&gt;PreviouslyOrdered();
  $Media = $Media_query-&gt;get();
  </code></pre>
  
  <p>And in my model I want to do something like : </p>
  
  <pre><code>class OutDoorMedia extends Model
  {
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'id',
          'user_id',
          'address',
          'location',
          'media_type',
      ];
  }
  
  class scopePreviouslyOrdered extends OutDoorMedia
  {
  public $appends = ['previously_ordered'];
  
  public function getPreviouslyOrderedAttribute()
  {
      if ($this-&gt;hasMany('App\Models\OutDoorMediaOrders', 'odm_id', 'id')-&gt;Where(function ($query) {
          $query-&gt;where('status', MEDIA_ORDER_CHECKOUT_STATUS)
              -&gt;orWhere('status', STATUS_TO_PAY);
      })-&gt;exists()) {
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But it's not working and I know it's wrong, How to achieve this? </p>