Created
July 24, 2018 11:16
-
-
Save Qooh0/a96403b3dbe2e895c2645ef53186a6c3 to your computer and use it in GitHub Desktop.
Laravel 5.6 におけるエラーメッセージのカスタマイズ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 書こうと思ったきっかけ | |
日本語で簡単にググれなかったので、メモを兼ねて | |
# 書き方 | |
Validation を単純に書く場合、Controller の Store() に $request->validate() で書くはず。 | |
その時に、第二引数でカスタマイズされたエラーメッセージを記載すれば良い。 | |
この例は、URL の入力項目に対して validate している例 | |
```php | |
$request->validate(['url' => 'required|url'], | |
[ | |
'url.required' => 'URL は必須です', | |
'url.url' => 'URL の書き方を確認してください' | |
]); | |
``` | |
# 最後に | |
もし参考になった場合は、スターを押してください。 | |
# 参考 | |
https://laravel.com/docs/5.6/validation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment