0 レビュー
1 回答
php-laravelのカスタムリクエストクラスでメッセージを渡す方法は?
フォームリクエストのカスタムメッセージを渡すリクエストクラスは次のとおりです。
カスタムルールに従ってカスタム検証メッセージを渡したい。
<?php
namespace App\Http\Requests\Authenticate;
use App\Http\Requests\Request;
class AuthRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
// I want to return custom messages from here
return [
"email" => "required|email|exists:user,email",
'password' => 'required',
];
}
}
助けていただければ幸いです。よろしくお願いします。
わからない
0
レビュー
答え :
解決策:
これがあなたの答えです。メッセージを渡すための関数を追加します。
public function messages()
{
return [
"required" => "The :attribute field is required.",
'email' => 'The :attribute should be valid email.',
'exists' => 'The :attribute already exists.'
];
}
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。