Saving data

Applications that display data are great, but they're not very interactive. The fun comes when you allow users to submit data, whether these users are trusted contributors adding content via a content management system or contributions from general users on a site like Wikipedia.

When you retrieve a record via Eloquent, you can access its properties as follows:

$cat = Cat::find(1);
print $cat->name;

We can update attribute values in the same manner:

$cat->name = 'Garfield';

This will set the value in the model instance, but we need to persist the change to the database. We do this by calling the save method afterwards:

$cat->name = 'Garfield';
$cat->save();

If you have a table with lots of columns, then it will become tiresome to assign ...

Get Laravel 5 Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.