Laravel - Relationships - Defining Custom Intermediate Table Models
If you would like to define a custom model to represent the intermediate table of your many-to-many relationship, you may call the
using method when defining the relationship. Custom pivot models give you the opportunity to define additional methods on the pivot model.
Custom many-to-many pivot models should extend the
Illuminate\Database\Eloquent\Relations\Pivot class while custom polymorphic many-to-many pivot models should extend the
Illuminate\Database\Eloquent\Relations\MorphPivot class. For example, we may define a
Role model which uses a custom
RoleUser pivot model:
belongsToMany(User::class)->using(RoleUser::class); } }
When defining the
RoleUser model, you should extend the
Pivot models may not use the
SoftDeletestrait. If you need to soft delete pivot records consider converting your pivot model to an actual Eloquent model.