Skip to content
php
$table->string('name')->nullable()->comment('姓名');
$table->string('email')->unique()->comment('邮箱');
$table->text('content')->comment('新闻内容');
$table->longText('payload');
$table->timestamp('failed_at')->useCurrent();
$table->foreignId('cat_id')->constrained()->onDelete('cascade');

https://laravelacademy.org/post/22014

fake

php
user
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => Hash::make('admin88'),
'remember_token' => Str::random(10),

info
'title'=>fake()->unique()->word()
'title'=> fake()->sentence(),
'content'=>fake()->paragraph(),
'preview'=>fake()->imageUrl(),
'cat_id'=>Cat::inRandomOrder()->first()->id //关联
php artisan migrate:refresh --seed

request

php
class FindPasswordCodeRequest extends FormRequest
{

    public function rules()
    {
        return [
          'email'=>['required','email',Rule::exists('users','email')],
          'email'=>['required','email',Rule::unique('users','email')],//register
          'password'=>['required','min:3','confirmed'],
          'captcha_code' => 'sometimes|required|captcha_api:'. request('captcha_key') . ',math',
          'title' => ['required', 'between:3,255',Rule::unique('cats', 'title')],
          'order' => ['numeric'],
          'preview' => ['url'],
          'cat_id'=>['sometimes','numeric'],
          'title' => ['required', 'between:3,255',
                      Rule::unique('cats', 'title')->ignore($this->route('cat')->id)
                     ], //UpdateCatRequest,UpdateInfoRequest
        ];
    }
  
  	public function messages() {
        return ['captcha_code.captcha_api'=>'验证码输入错误'];
    }

    public function attributes() {
        return [
          'captcha_code'  => '验证码',
          'title' => '产品大类名称',
            'preview'=>'产品大类预览图',
            'order' => '产品大类排序'
        ];
    }
}

Lucking