Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
Lessons:21Length:2.7 hours
  • Overview
  • Transcript

3.4 Eloquent Relations

Relations may be Eloquent’s most powerful feature. With just a few lines of code you can create one-to-one, one-to-many, or even many-to-many relations. It’s as easy as defining $this->belongsToMany('Category');. In this lesson, we’ll use all of them: Users to Phones (one-to-one), Users to Posts (one-to-many) and Posts to Categories (many-to-many, using a pivot table). Also, we’ll implement eager loading, which will dramatically speed up your application when using relations and cure the so-called n+1 problem.

Note: Eloquent relations live in vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations