Laravel 10.xのartisanの「make:rule」コマンドを解説します。
Description
新しい検証ルールの作成
Usage
php artisan make:rule [-f|--force] [-i|--implicit] [--] <name>
Arguments
引数 | 必須 | 設営 |
---|---|---|
name | 必須 | 検証ルール名 |
Options
オプション | 省略形 | 必須 | 説明 |
---|---|---|---|
force | f | - | ルールが既に存在する場合でも、クラスを作成 |
implicit | i | - | 暗黙のルールを生成 |
Examples
no options
php artisan make:rule Foo
INFO Rule [app/Rules/Foo.php] created successfully.
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class Foo implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
//
}
}
implicit
php artisan make:rule --implicit Foo
INFO Rule [app/Rules/Foo.php] created successfully.
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class Foo implements ValidationRule
{
/**
* Indicates whether the rule should be implicit.
*
* @var bool
*/
public $implicit = true;
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
//
}
}
コメント