Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Lift Laravel Package

wendelladriel/laravel-lift

Experimental Laravel package that supercharges Eloquent models with typed public properties matching your schema, powered by PHP 8 attributes. Add validation rules and other metadata directly on models and access them via handy methods, using Eloquent events for easy drop-in use.

View on GitHub
Deep Wiki
Context7

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(User::class)]
final class Role extends Model
{
    use Lift;
    // ...
}

HasMany

HasManyThrough

use WendellAdriel\Lift\Attributes\Relations\HasMany;
use WendellAdriel\Lift\Attributes\Relations\HasManyThrough;

#[HasMany(User::class)]
#[HasManyThrough(Post::class, User::class)]
final class Country extends Model
{
    use Lift;
    // ...
}
use WendellAdriel\Lift\Attributes\Relations\HasMany;

#[HasMany(Post::class)]
final class User extends Model
{
    use Lift;
    // ...
}
use WendellAdriel\Lift\Attributes\Relations\BelongsTo;

#[BelongsTo(User::class)]
final class Post extends Model
{
    use Lift;
    // ...
}

HasOne

use WendellAdriel\Lift\Attributes\Relations\HasOne;

#[HasOne(Phone::class)]
final class User extends Model
{
    use Lift;
    // ...
}

HasOneThrough

use WendellAdriel\Lift\Attributes\Relations\HasOne;
use WendellAdriel\Lift\Attributes\Relations\HasOneThrough;

#[HasOneThrough(Manufacturer::class, Computer::class)]
#[HasOne(Computer::class)]
final class Seller extends Model
{
    use Lift;
    // ...
}
use WendellAdriel\Lift\Attributes\Relations\HasOne;

#[HasOne(Manufacturer::class)]
final class Computer extends Model
{
    use Lift;
    // ...
}

MorphMany/MorphTo

use WendellAdriel\Lift\Attributes\Relations\MorphMany;

#[MorphMany(Image::class, 'imageable')]
final class Post extends Model
{
    use Lift;
    // ...
}
use WendellAdriel\Lift\Attributes\Relations\MorphTo;

#[MorphTo('imageable')]
final class Image extends Model
{
    use Lift;
    // ...
}

MorphOne/MorphTo

use WendellAdriel\Lift\Attributes\Relations\MorphOne;

#[MorphOne(Image::class, 'imageable')]
final class User extends Model
{
    use Lift;
    // ...
}
use WendellAdriel\Lift\Attributes\Relations\MorphTo;

#[MorphTo('imageable')]
final class Image extends Model
{
    use Lift;
    // ...
}

MorphToMany/MorphedByMany

use WendellAdriel\Lift\Attributes\Relations\MorphToMany;

#[MorphToMany(Tag::class, 'taggable')]
final class Post extends Model
{
    use Lift;
    // ...
}
use WendellAdriel\Lift\Attributes\Relations\MorphedByMany;

#[MorphedByMany(Post::class, 'taggable')]
final class Tag extends Model
{
    use Lift;
    // ...
}

Customizing the Relationship

All the attributes listed above, except the MorphTo attribute, accept an additional parameter to customize the relationship name.

use WendellAdriel\Lift\Attributes\Relations\BelongsTo;

#[BelongsTo(User::class, 'author')]
final class Post extends Model
{
    use Lift;
    // ...
}

$post->author; // Will return the User model

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.

use WendellAdriel\Lift\Attributes\Relations\BelongsTo;

#[BelongsTo(User::class, 'author', 'custom_id', 'id')]
final class Post extends Model
{
    use Lift;
    // ...
}

For the BelongsToMany relationship you can also customize the pivot with the pivotModel and pivotColumns parameters:

use WendellAdriel\Lift\Attributes\Relations\BelongsToMany;

#[BelongsToMany(User::class, pivotModel: OrganizationUser::class, pivotColumns: ['is_owner'])]
class Organization extends Model
{
    use Lift;

    #[PrimaryKey]
    public int $id;

    #[Fillable]
    public string $name;
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope