PHP code example of rapid / laplus

1. Go to this page and download the library: Download rapid/laplus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rapid / laplus example snippets


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

class Blog extends Model
{
    use HasPresent;
    use HasSlug; // Will extend the 'slug' column

    public function present(Present $present)
    {
        $present->id();
        $present->string('title');
        $present->belongsTo(Category::class);
        $present->enum('status', Status::class);
        $present->yield();
        $present->timestamps();
    }
}

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

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

return new class extends Travel
{
    public string|array $on = User::class;
    public string|array $whenAdded = 'full_name';
    public string|array $prepareNullable = 'full_name';

    public function up(): void
    {
        User::all()->each(function (User $user) {
            $user->update([
                'full_name' => $user->first_name . ' ' . $user->last_name,
            ]);
        });
    }
};

class User extends Model
{
    use HasPresent;
}

//protected $fillable = ['name', 'email', 'password'];
//protected $hidden = ['password', 'remember_token'];
//protected function casts() { ... }

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();
}

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

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, ' ');
    }
}

/**
 * @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
shell
php artisan vendor:publish --tag=laplus
shell
php artisan dev:migrate --guide
shell
php artisan deploy:migrate
shell
php artisan make:model-laplus Name
shell
php artisan make:model-laplus --present Name
shell
php artisan dev:migration
shell
php artisan dev:migrate