11.08.2017 Views

codebright

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Eloquent ORM<br />

We’ve learned how to configure our database and how we can use the shema builder to structure<br />

tables within our database, but now it’s time to get down to the nitty gritty and learn how we can<br />

store information in the database.<br />

Now some of you who have already encountered the database components of Laravel, or even those<br />

of you who have been using Laravel 3 might be wondering why I’m choosing to start with the ORM?<br />

Why don’t I begin with SQL statements, then query building?<br />

Well, let’s take a step back and think about why we are here. You are a developer, a PHP developer<br />

in fact! Since you are reading this book, I’m hoping that you are a PHP 5+ developer, and will have<br />

embraced object-oriented development.<br />

If we are are describing the entities in our application as objects, then it makes sense to store them<br />

as objects, retrieve them as objects, and more.<br />

Let’s imagine that we are writing an online book store.<br />

Object-oriented application design has taught us that we need to identify the objects within our<br />

application. Well, a bookstore isn’t going to be very successful without any books, right? So there’s<br />

a fair change that we will be wanting a book object to represent the individual books used by our<br />

application. Normally we will refer to these application objects as ‘Models’, since they represent part<br />

of our applications business model. Here’s an example.<br />

1

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

Saved successfully!

Ooh no, something went wrong!