Laravel 5.7.* All Model Relations Explained (Silent as the Dead)

Retired

This book is no longer available for sale.

Laravel 5.7.* All Model Relations Explained

a detailed discussion of mvc, Composer, Migrations, Database Relationships, Resource controllers and faker, advanced crud, One to One, One to Many, Many to Many, Has Many through, and polymorphic relationships in laravel 5.7.*

About the Book

Any awesome Laravel application greatly depends on Model relations. How they work, what are the magical methods behind them? Explained lucidly with examples.

You will learn all Model relations and how you can use them to build a complicated web application.

Apparently, this contents management application does not look very complicated, however, the relations are quite tangled and we will try to understand these relations through Laravel’s Model relations and Eloquent ORM; at the end, we will also learn how resourceful controllers play vital roles in such model relations.

How an article is related to a particular user and how from the article table we can fetch the data of that particular user or writer? An article uses many tags, but how we can access those tags from that article itself? An article may have many comments. Who has written those comments? Of course users. And these users have their own profiles which tell us about them, including name, email, city, and a short biography. Each profile page may have multiple comments written by other users about that profile-holder user. So we have comments table for both – articles and profiles. Can we use one single comment table to serve them both? Yes, we can do! A polymorphic relationship allows us to do that.

These questions are all very tricky, however, laravel model relations, Eloquent ORM, and resourceful controllers has solved these problems quite easily. As we progress we will learn one-to-one, one-to-many, many-to-many, has-many-through, and polymorphic relationships with concrete examples. By the way, we will also learn some major tricks of Laravel (like resource controller and views) that makes your development experience more pleasant.

Finally, what we will see in this application? A user have many articles. When you open the application, you will find the series of article titles. Each title will show who is the writer of it. If you click on each title, you can read the full article. If you click on the user name, you will see the user’s profile and all the articles he/she has written. The same rule is applied for the tags. Each tag may belong to many articles. Again any article may belong to many tags. So each article shows many tags. In the user profile we will see which tags he/she has used often and so on. In addition to that, we have comments on both pages, with a link to the users who have written them.

All together, it’s an interconnected contents management application that handles many complex queries effortlessly.

About the Author

Sanjib Sinha
Sanjib Sinha

A Freak, in an absurd journey that starts from nowhere, and ends up nowhere.

Table of Contents

Contents

Who should read this book?

What you will Learn from this Book and The Application we are going to build

1. What is MVC Pattern

2. How MVC Pattern Works

3. Composer and Laravel

3.1 Composer’s role in Effective Patterns

3.2 Composer and Separation of Concerns

3.3 Laravel Homestead, Virtual Box and Vagrant

3.4 Installing Virtual Box and Vagrant

3.5 Installing Homestead Vagrant Box

3.6 Homestead installation and configuration

4. How to start our Application

5. How Migrations work in Laravel

5.1 Model Relations for Application

5.2 Controllers and Views

5.3 Creating Views to show Relationships

5.4 One To One

5.5 One to Many

5.6 Dependency Injection and Separation of Concerns

5.7 Many to Many

5.8 Has Many Through

5.9 Polymorphic Relations

6. Resource Controllers and Eloquent Magic

6.1 Model and Controller

Where to go from here

Last but not the Least

Causes Supported

Amazon Watch

Supporting Indigenous Peoples. Protecting the Amazon.
http://amazonwatch.org

Amazon Watch is a nonprofit organization founded in 1996 to protect the rainforest and advance the rights of indigenous peoples in the Amazon Basin. We partner with indigenous and environmental organizations in campaigns for human rights, corporate accountability and the preservation of the Amazon's ecological systems.

We envision a world that honors and values cultural and biological diversity and the critical contribution of tropical rainforests to our planet's life support system. We believe that indigenous self-determination is paramount, and see that indigenous knowledge, cultures and traditional practices contribute greatly to sustainable and equitable stewardship of the Earth. We strive for a world in which governments, corporations and civil society respect the collective rights of indigenous peoples to free, prior and informed consent over any activity affecting their territories and resources. We commit, in the spirit of partnership and mutual respect, to support our indigenous allies in their efforts to protect life, land, and culture in accordance with their aspirations and needs.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub