Hi guys,
I'm having a problem with the date format when developing for SQL Server. When using the DBLib extension the format breaks, when using the sqlsrv extension, it works. One could argue that changing the date format on the models would help, he would actually be right, but other packages that extend on Eloquent Model like Passport actually break and modifying the Eloquent Model class is wrong.
Is there a way to change the global date format that is used throughout the system?
It's not possible to replace it in your complete application, but you can replace it in your Eloquent models with a simple trait. You simply load the trait on the model you want a different date format for and you are done ;)
@bobbybouwmann I still don't get you. My current problem is that I can't create any tokens due to carbon throwing an invalid arguments exception. All models I have used to throw the same exception. For the models, they extend an abstract class that extends Eloquent model with the date format set. Is there any way to fix the date format in the packages without editing them?
The Laravel\Passport\Token model will use the builder grammar since it directly extends Model. @JeffreyWay any way to sort this without modifying the package?
A trait is some kind of class that can be included in many places. So in this case if you a method in it that's the same as the extended class it will override that. So you can override the basic behaviour of the Eloquent class with that trait.
@bobbybouwmann I understand what a trait is and they help a lot with multiple inheritance. The problem is changing the packages. If I include the trait in the Laravel\Passport\Token model, I would have modified the package. When it is updated, it will revert all changes that I made thus, its always a bad idea to modify packages. The trait would work on the Models I create without any problem since I maintain them.
Aah I didn't understood that you wanted to replace the Token model in the passport package. I think you should create an issue on Github since this is a package specific problem
@bobbybouwmann exactly. The problem is with these packages that are maintained by other people. If in app.config we could set the default date format to be used across Laravel, the issue would be sorted. Thanks though.