What is a custom pivot model?
By default, the pivot table used by a belongsToMany (many-to-many) relationship is represented by a plainIlluminate\Database\Eloquent\Relations\Pivot instance. When you want to store extra columns on the pivot table (an approval timestamp, a role type, etc.), or add accessors, mutators, or custom methods, create a custom model that extends Pivot.
using() on your belongsToMany definition to tell the relationship to use this custom model.
When you save a custom pivot model, name it using the singular form of the two model names in alphabetical order (
RoleUser, not UserRole). This is only a naming convention — you can pick any class name you like.Specifying pivot attributes with as()
By default, pivot values are accessed through a pivot property. Use the as() method to change that name.
Extra columns and timestamps
When your pivot table has additional columns likeapproved, include them explicitly with withPivot(). Call withTimestamps() if you want Eloquent to manage created_at / updated_at.
Inverse relationships from the pivot model
You are free to definebelongsTo relationships back to the declaring model and the related model on your custom pivot.
$roleUser->role or $roleUser->user from a standalone pivot instance. If you want to automatically eager-load these when running the parent query, use the chaperone() method described below.
Automatic eager loading with chaperone() (Laravel 13)
Laravel 13 introduced the chaperone() method, which automatically hydrates belongsTo relationships defined on a pivot model — such as role() / user() — when the belongsToMany query runs.
chaperone(), Eloquent infers the names of the belongsTo relationships on the pivot model (RoleUser) and, when you retrieve a collection with something like Role::with('users'), wires up references from each pivot to the declaring and related models with no additional queries.
Non-standard relationship names
If thebelongsTo methods on your pivot model don’t follow the standard naming convention (singular camelCase of the declaring or related model name), pass explicit names as arguments to chaperone().
Next steps
Relationships
Review the basics of defining relationships, including belongsToMany.
Eloquent Observers and Model Events
Learn how to use model events to hook into saving and updating pivot models.