-
Book Overview & Buying
-
Table Of Contents
Laravel 5.x Cookbook
By :
This is an Angular section, but I will take a moment to create a simple relationship, which we will later build a widget around. In this case, I am going to add a favorites table to the system and relate this to a user. It will hold the information I need to show a comic from Maravel.
A base installation of Laravel with the User model migrated is required here.
Run this inside the virtual machine console:
>php artisan make:migration create_favorites_table
Open this file, and add the database/migrations/2016_05_16_220136_create_favorites_table.php fields:

Then, make a model for this file:
>php artisan make:model Favorite
In this file, we can add a relationship back to the user:

Then, open the user file called app/User.php to relate back to the favourites:

Now, we are ready to build this UI.
This is a fairly normal migration with a relationship with just a little extra. For one, notice the plural name of the favorites...