Home

Awesome

Laplus

Laravel plus+ add presentation for your models

public function present()
{
    $this->id();
    $this->text('title');
    $this->string('password')->cast('hashed')->hidden();
    $this->belongsTo(Artist::class)->cascadeOnDelete();
}

Features

1. Auto Migrations

Write your presents in long time:

Write presents in long time, laplus will create your migrations

Laplus will generate your migrations:

Laplus will create your migrations

Read more...

2. Auto Fills

You don't need to define $fillable, $cast and $hidden!

// These values will automatically fills:
// protected $fillable = ['id', 'slug'];
// protected $cast = ['password' => 'hashed'];
// protected $hidden = ['password'];

Read more...

3. IDE Friendly

Laplus automatically generate the model docblock to better understanding codes for IDE:

/**
 * @property int $id
 * @property string $name
 * @property \App\Enums\Gender $gender
 * @method BelongsTo<Profile> profile()
 * @property Profile $profile
 */

Read more...

Requirements

Documents

Installation

1- Install the package with composer:

composer require rapid/laplus

2- Publish configs

Run this command to publish configs to config/laplus.php

php artisan vendor:publish --tag=laplus

3- Convert default User model to presentable model (optional):

class User extends Model
{
    use HasPresent;
}
//protected $fillable = ['name', 'email', 'password'];
//protected $hidden = ['password', 'remember_token'];
//protected function casts() { ... }

Laplus will automatically add this values.

php artisan make:user-present

Or add below code in User class:

protected function present(Present $present)
{
    $present->id();
    $present->string('name');
    $present->string('email')->unique();
    $present->timestamp('email_verified_at')->nullable();
    $present->password();
    $present->rememberToken();
    $present->timestamps();
}

Find database/migrations/0001_01_01_000000_create_users_table.php file and move it into database/migrations/auto_generated folder (create it if doesn't exists)

Make model & present

You can use this command to create a model and a present:

php artisan make:model+ Name

This command will create app/Models/Name.php model and app/Presents/NamePresent.php present.

Read more...

Make model with inline present

You can use this command to create a model with inline present:

php artisan make:model+ Name --inline

This command will create app/Models/Name.php model.

Read more...

Migrations

Generate Migrations

Run this command to automatically found the updates and generate migrations:

php artisan generate+

Read more...

Regenerate Migrations

This command is same with generate+, but the difference is clearing the migration folder!

php artisan regenerate+

Warning: This command will remove all your migration files (exclude files starts with 0001_01_01 name)

Read more...

Generate And Migrate

Following command, run generate+ and migrate at once:

php artisan migrate+

Read more...

Label Translator

Present the model labels:

class UserLabelTranslator extends LabelTranslator
{
    public function gender(bool $emoji = false)
    {
        return $this->value?->toString($emoji); // Returns gender name or null
    }
}

And use it easily:

<p>{{ $user->gender_label }}</p>
<p>{{ $user->gender_label(emoji: true) }}</p>

Labels always return a string value. If the value is null, it returns "Undefined".

Read more...

Guide Generator

Guide automatically generate the model docblock using the columns, attributes and relationships:

class User extends Model
{
    use HasPresent;
    use HasLabels;
    
    protected function present(Present $present)
    {
        $present->id();
        $present->string('name');
    }
    
    #[IsRelation]
    public function avatars()
    {
        return $this->hasMany(Avatar::class);
    }
    
    public function getFirstName() : string
    {
        return Str::before($this->name, ' ');
    }
}

It generates:

/**
 * @Guide
 * @property int $id
 * @property string $name
 * @property Collection<int, Avatar> $avatars
 * @property string $name_label
 * @property string name_label()
 * @property string $first_name
 * @EndGuide
 */
class User extends Model

Read more...

More Document

More document found in Documents section.