Skip to Main Content
Hands-On Full Stack Web Development with Angular 6 and Laravel 5
book

Hands-On Full Stack Web Development with Angular 6 and Laravel 5

by Fernando Monteiro
July 2018
Intermediate to advanced content levelIntermediate to advanced
420 pages
8h 46m
English
Packt Publishing
Content preview from Hands-On Full Stack Web Development with Angular 6 and Laravel 5

Many-to-many relationship

For the many-to-many relationship, we will have many Bikes in many Garages by using the pivot table.

In the many-to-many relationship, we need to respect some naming rules.

The name of the pivot table should consist of singular names of both tables, separated by underscore symbols, and these names should be arranged in alphabetical order.

By default, there should only be two pivot table fields and the foreign key to each of the tables, in our case, bike_id and garage_id.

Still in the project/app/Bike.app file, let's add the many-to-many relationship between the Bike and Garage models.

Add the following code immediately after the items() function:

public function garages() { return $this->belongsToMany('App\Garage'); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Laravel: Up and Running

Laravel: Up and Running

Matt Stauffer
Building Large-Scale Web Applications with Angular

Building Large-Scale Web Applications with Angular

Chandermani Arora, Kevin Hennessy, Christoffer Noring, Doguhan Uluca

Publisher Resources

ISBN: 9781788833912Supplemental Content