Querying using Fluent
Laravel provides many ways to access databases. If we choose not to write raw SQL statements, we can use the Fluent query builder to make things easier.
Getting ready
For this recipe, we'll be using the table created in the Creating data tables using migrations and schemas recipe.
How to do it...
To complete this recipe, follow these steps:
In the command prompt, create a migration so we can add some data:
php artisan migrate:make add_data_to_shows_table
In our
app/database/migrations
directory, find a file similar to2012_01_01_222551_add_data_to_shows_table.php
, and add some data using the Fluent query builder:class AddDataToShowsTable { /** * Make changes to the database. * * @return void */ public function up() { $data1 = array('name' => 'Doctor Who', 'rating' => 9, 'actor' => 'Matt Smith'); $data2 = array('name' => 'Arrested Development', 'rating' => 10, 'actor' => 'Jason Bateman...