1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

laravelのvalidatorをtinkerでちょこっとだけ試す

Posted at

概要

laravelのvalidatorをチョコっと試す
忘れてしまうのでメモしておく

tinkerて何。

コンソールでlaravelとかPHPをチョコっと試せる機能だ
詳しくは・・・⬇️
https://readouble.com/laravel/5.7/ja/artisan.html#tinker
(怖い人よけの為に公式も貼っておく)
https://laravel.com/docs/5.7/artisan#tinker

laravelのバリデーションって豊富だ。

ルールがアレコレあってチョコっとだけ試したい時があるなぁ。
https://readouble.com/laravel/5.5/ja/validation.html#available-validation-rules

tinkerを起動したら以下の様にかく

# こうかくと
>>> Validator::make([''], ['data' => 'required'])->errors()->toArray()
# こう返ってくるよ
=> [
     "data" => [
       "The data field is required.",
     ],
   ]

# あとは好きに試す
>>> Validator::make(['data' => 'yeah'], ['data' => 'numeric'])->errors()->toArray()
=> [
     "data" => [
       "The data must be a number.",
     ],
   ]

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?