use IlluminateSupportFacadesValidator;
class PostController extends Controller
{
/**
* Store a new blog post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
if ($validator->fails()) {
return redirect('post/create')
->withErrors($validator)
->withInput();
}
// Retrieve the validated input...
$validated = $validator->validated();
// Retrieve a portion of the validated input...
$validated = $validator->safe()->only(['name', 'email']);
$validated = $validator->safe()->except(['name', 'email']);
// Store the blog post...
}
}
$this->validate([ // 1st array is field rules
'userid' =>'required|min:3|max:100',
'username' =>'required|min:3',
'password' =>'required|max:15|confirmed',
], [ // 2nd array is the rules custom message
'required' => 'The :attribute field is mandatory.'
], [ // 3rd array is the fields custom name
'userid' => 'User ID'
]);
/**
* Store a new blog post.
*
* @param IlluminateHttpRequest $request
* @return IlluminateHttpResponse
*/
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
// The blog post is valid...
}
9
If it has worked for you before then you should check if you have messages defined in the applangenvalidation.php or by chance you have changed the locale of the app and have not defined the messages for it. There are many possibilities.