title: How to set append variable on condition in laravel model?
body: <p>I am doing project in Laravel. I have model named 'User.php' and here I want to set $appends variable depends on condition.
  In database I have stored values in key attribute format.
  eg: </p>
  
  <ul>
  <li><p>I have table named 'user' which contains basic info like name, email and mobile number.</p></li>
  <li><p>Other table named as 'user_attributes_master' which contains columns like 'avatar', 'theme', etc.</p></li>
  <li><p>and other table named as 'user_attribute_values' which contains columns like 'id', 'user_id' and 'att_id'(which is a primary key of user_attributes_master table)</p></li>
  </ul>
  
  <p>user.php looks like</p>
  
  <pre><code>class User extends Authenticatable
  {
  protected $appends = ['avatar_photo'];
  
  public function profile_attributes()
      {
          return $this-&gt;belongsToMany(\App\Models\Access\User\UserProfileAttributes::class,config('access.user_attribute_values_table'),'user_id','user_attribute_id')-&gt;withPivot('value', 'active')-&gt;withTimestamps();
      }
  
  /**
       * @return string
       */
      public function getAvatarPhotoAttribute()
      {
          $avatar = $this-&gt;profile_attributes()-&gt;where('user_attributes_master.id',7)-&gt;first()-&gt;avatar_path;
          return $avatar;
  
      }
  }
  </code></pre>
  
  <p>Here I get avatar_path attribute to every record which is append variable I have set to profile.php model. How to get this to only 'avatar' col of profile.php. How can I set this appends variable. </p>
  
  <p>attribute model conatins code,</p>
  
  <pre><code>protected $appends = ['avatar_path','theme_path'];
  
  public function getAvatarPathAttribute()
      {
              return $this-&gt;pivot-&gt;value != null ? config('app.url').'/'.config('profile.images.user_images'). "/" . $this-&gt;pivot-&gt;user_id ."/" . config("profile.images.avatar")."/".$this-&gt;pivot-&gt;value : '';
  
      }
  </code></pre>
  
  <p>Here I dont want 'avatar_path' for every attribute.</p>