Jay Chu
Jay Chu

Reputation: 55

laravel model select without Attribute function

I use laravel model to select some data like this

$query->select(['id', 'first_name', 'last_name', 'preferred_name', 'app_status'])

public function getAppStatusAttribute()
{
  if ($this->attributes['app_status'] == -1 || 
      $this->attributes['app_status'] >= count($this->app_status_list))
         return "";
      else
         return $this->app_status_list[$this->app_status];
}

In laravel model, it will auto select AppStatus from getAppStatusAttribute(),

How to select the raw data without getAppStatusAttribute() in query

Upvotes: 2

Views: 1163

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 152980

If you need the mutated and the original value, I suggest you give it a different name. For example, call your function getAppStatusStringAttribute, then you can access the original data as usual and get the mutated attribute with ->appStatusString.

Upvotes: 1

Related Questions