Laravel 5.7.* All Model Relations Explained (Silent as the Dead)
This book is 100% complete
Completed on 2018-10-02
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.
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
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.
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...