In the database let's say I have in my user's table these fields: name
, favorite_color
, created_at
, etc...
Using Eloquent to save:
$user = new User;
$user->name = "John";
$user->favorite_color = 'blue'; // Notice the underscore
$user->save();
$user = new User;
$user->name = "John";
$user->favoriteColor = 'blue'; // camelCase
$user->save();
Which one of the above is correct?
The first one is the correct form. But there's a package to help you do the second one: https://github.com/kirkbushell/eloquence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With