I will explain in detail the case I came across :
I'm using spatie translation package.
inside HasTranslation trait that I'm using in my models there is a line that calls asJson($value) method. this method accepts a value and returns it as a JSON :
return json_encode($value)
in some cases we need to pass another argument JSON_UNESCAPED_UNICODE which handles languages other than English :
return json_encode($value,JSON_UNESCAPED_UNICODE)
so what is the right way to implement this ! is it to use composer override or to create a trait that overrides this method and use it inside every model that uses HasTranslation trait.
@alnouirah you can implement the asJson method yourself in the Model class which will override the trait's asJson method; or write a separate trait to implement asJson as you wish, then collision-resolve in the Model(s):
use HasTranslation, MyHasTranslation {
MyHasTranslation::asJson insteadof HasTranslation;
}