How to check if a record is new in Laravel?

All laravel models have a ->exists property.

More specifically if the model is either loaded from the database, or has been saved to the database since being created the exists property will be true; Otherwise it will be false.

If you wish to know if the model has been modified since being grabbed from the database, or simply not saved at all (aka if it needs saving) then you can use the ->isDirty() function.

The Laravel API is a useful place for this kind of information:
http://laravel.com/api/4.2/Illuminate/Database/Eloquent/Model.html#method_isDirty
and often sheds far more light than the default documentation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)