11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Eloquent ORM 271<br />

We have used the static find() method of our model retrieve an instance of Game representing the<br />

database row with an id value of 1. We can then access the public attributes of the model instance<br />

to retrieve the column values. Let’s visit the / URL to see the result.<br />

1 Assassins Creed<br />

Great, our existing value has been retrieved. The static find() method is inherited from the Eloquent<br />

parent class, and does not need to be created within your model. As I said earlier, there are many<br />

other retrieval methods, which will be covered in a later chapter about querying Eloquent models.<br />

For now, let’s look at how we can update existing table rows.<br />

Updating Existing Models<br />

If you have recently created a new model, then the chances are that you have assigned it to a variable.<br />

In the previous section we created a new instance of our Game model, assigned the instance to the<br />

$game variable, updated its columns and used the save() method to persist it to the database.<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!