如何在我的请求文件中自定义我的验证消息?在Laravel请求中自定义验证消息
如何在规则旁添加消息? 我想要的就是像常见验证一样放置自定义消息。可能吗?在请求中只进行正常的验证方式?
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class ArticleRequest 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()
{
return [
'title' => 'required|min:5',
'content' =>'required',
'user_id' => 'required|numeric',
'category_id' => 'required|numeric',
'published_at' => 'required|date'
];
}
}
您可以通过命令行创建此自定义请求消息: “php artisan make:request StoreArticleRequest” StoreArticleRequest.php类位于app/Http/Requests目录中。 –
@sagor Right ...虽然与问题(或答案)无关。 –