Laravel 10.xのartisanの「make:rule」コマンドを解説します。
Description
新しい検証ルールを作成します。
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
{
//
}
}
Stub
Option | Stub file name |
---|---|
- | rule.stub |
implicit | rule.implicit.stub |
Source
10.x
framework/src/Illuminate/Foundation/Console/RuleMakeCommand.php at 10.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
11.x
framework/src/Illuminate/Foundation/Console/RuleMakeCommand.php at 11.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
コメント