rapid/laplus

2.0.0 2024-10-01 07:51 UTC

This package is auto-updated.

Last update: 2024-10-01 08:02:07 UTC


README

Laravel plus+ 为您的模型添加演示

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

在长时间内编写您的演示

Write presents in long time, laplus will create your migrations

Laplus 将为您生成迁移

Laplus will create your migrations

要求

  • Php 8.2 或更高版本
  • Laravel 11.0

文档

安装

1- 使用 composer 安装包

composer require rapid/laplus

2- 发布配置

运行以下命令将配置发布到 config/laplus.php

php artisan vendor:publish --tag=laplus

3- 将默认 User 模型转换为可演示的模型(可选)

  • 添加 HasPresent 特性
class User extends Model
{
    use HasPresent;
}
  • 移除 $fillable$hiddencasts() 的值
//protected $fillable = ['name', 'email', 'password'];
//protected $hidden = ['password', 'remember_token'];
//protected function casts() { ... }

Laplus 将自动添加这些值。

  • 创建 UserPresent
php artisan make:user-present

或在 User 类中添加以下代码

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();
}
  • 将默认迁移移动到 laplus 路径

找到 database/migrations/0001_01_01_000000_create_users_table.php 文件并将其移动到 database/migrations/auto_generated 文件夹中(如果不存在则创建它)

创建模型和演示

您可以使用此命令创建模型和演示

php artisan make:model+ Name

此命令将创建 app/Models/Name.php 模型和 app/Presents/NamePresent.php 演示。

创建具有内联演示的模型

您可以使用此命令创建具有内联演示的模型

php artisan make:model+ Name --inline

此命令将创建 app/Models/Name.php 模型。

迁移

生成迁移

运行此命令以自动找到更新并生成迁移

php artisan generate+

重新生成迁移

此命令与 generate+ 相同,但不同之处在于清除迁移文件夹!

php artisan regenerate+

警告:此命令将删除所有迁移文件(排除以 0001_01_01 开头的文件)

生成并迁移

以下命令将同时运行 generate+migrate

php artisan migrate+

更多文档

更多文档在 文档 部分中。