Using advanced Eloquent and relationships
One of the great things about using Laravel's Eloquent ORM is the ease with which we can interact with multiple tables that have foreign keys and pivot tables. In this recipe, we'll see how easy it is to set up our models and run queries against joined tables.
Getting ready
For this recipe, we'll be using the shows
and users
tables created in the previous recipes Creating data tables using migrations and schemas and Using automatic validation in models.
How to do it...
To complete this recipe, follow these steps:
In the command prompt, create a migration for a new pivot table:
php artisan migrate:make create_show_user
Open the migrations file in the
app/database/migrations
directory and add the schema:use Illuminate\Database\Migrations\Migration; class CreateShowUser extends Migration { /** * Make changes to the database. * * @return void */ public function up() { Schema::create('show_user', function($table) ...