Relationships
With Lift, you can configure all of your Model relationships using Attributes. It works the same way when defining them with methods, so all of them accept the same parameters as the methods.
BelongsTo
use WendellAdriel\Lift\Attributes\Relations\BelongsTo;
#[BelongsTo(User::class)]
final class Post extends Model
{
use Lift;
// ...
}BelongsToMany
use WendellAdriel\Lift\Attributes\Relations\BelongsToMany;
#[BelongsToMany(Role::class)]
final class User extends Model
{
use Lift;
// ...
}HasMany
HasManyThrough
HasOne
HasOneThrough
MorphMany/MorphTo
MorphOne/MorphTo
MorphToMany/MorphedByMany
Customizing the Relationship
All the attributes listed above, except the MorphTo attribute, accept an additional parameter to customize the relationship name.
After the name parameter, you can pass the same parameters as you would do when defining the relationship using methods, for example, to customize the foreign key.
For the BelongsToMany relationship you can also customize the pivot with the pivotModel and pivotColumns parameters:
Last updated
Was this helpful?