make accessor aware of api call/serialization to avoid translation when interacting with api
I have an enum type, so when the model access the enum with blade, I have the __() function on the accessor, this makes the translation of the enum automatically and avoid having special case codes (as it should). However this messes up with the api interface. So I was wondering if there is a way to make the accessor aware of the context.
I want to do something like this:
public function getFooAttribute($value){
if(/* api call */)
return $value;
return __("FooType.$value");
}
I know at the controller I can do $request->is('api/*') but here I have no access to the Request instance.
I think this could also work with something like:
public function getFooAttribute($value){
if(/* serializing */)
return $value;
return __("FooType.$value");
}