Why trait for auto generated column is not working?
i have this trait to generate asset_code but I got this error instead
The model
the trait
AssetCode.php
5 Replies
My first guess:
asset_code
is not in the $fillable
of the Model?
If it's not the correct guess, put dd()
in the Trait to check if it's even called at all.Hi sir, I followed you in youtube.. anyways, the asset_code is fillable and I tried also dd() and the trait is not triggered.. may I can't use two trait in one event?
Since the model is extends BaseModel and inside of it has trait tor timestamp
BaseModel
then in the model I also call another trait for asset code
and in this case one of the trait is not triggered?
Interestin. I've never had such setup with layers. I guess that can be a problem with Laravel "magic" of automatic bootable traits.
What is the implementation of your
Timestampable
trait? I just code a similar implementation to test and works fine for me:
Asset Model:
Custom model (only extend from Laravel model):
HasCode trait implementation:
I tested ir running on Tinker App\Models\Asset::create([])
The senior dev implement this.. its ok now but different approach on trait instea of using boot<trait_name>() they use initialize<trait_name>() but this is temporary fix for now
so Basically BaseModel is another layer where it's extend the model and use another trait
Your implementation is working in another project without another layer