Skip to main content

Posts

Showing posts with the label Eloquent Features

10 Eloquent Features That You Might Not Know About

With all the features that are out-of-the-box available in Laravel it is hard to know them all. Some features are not even properly documented. In this article I will be giving you ten Eloquent features that you might not know about. 1. Custom timestamp column names By default Laravel models have a   created_at   and an   updated_at   timestamp. You can overwrite these column names by defining a constant variable in your model. If your model uses soft deletes you can overwrite the   deleted_at   column name aswell. class User extends Model { const CREATED_AT = 'created'; const UPDATED_AT = 'last_update'; const DELETED_AT = 'removed'; } 2. The exists property The exists property tells whether the object exists in the database or not. When you create a new model instance the exists property will be set to false. Once your model is saved or retrieved from the database the exists property will be set to true. $user = new User; $user->name = 'Geor...