I have created a mutator in my model.
Class Client {
protected $fillable = ['name', 'age']
public function getIndustryAttribute() {
// some evaluations;
return "Programmer"
}
}
Now, I am trying to use Client::where('industry', "Programmer")->get()
to get the value. Is this possible at all?
Please bear in mind this is a totally pseudo code for explaining easier. I ended up this way because of mis-planning..
No, you can't do that.
Mutators are evaluated after the query has been executed.
What you can do when querying is to define the correct scopes.
It is not possible because applying a mutator when querying would be really performance heavy: it would be equivalent to looping through the whole table and performing the elaboration on every row.