Validation des e-mails dans Laravel
'email' => 'required|email|unique:users,email',
//@sujay
$uj@y
'email' => 'required|email|unique:users,email',
//@sujay
@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
@endif
use Illuminate\Support\Facades\Validator;
$customMessage = [
'title.max' => "title is too large",
];
$rules = [
'id' => 'integer|exists:master_advert_bundles',
'title' => ['required', 'unique:posts', 'max:255'],
'body' => ['required']
];
$validate = validation($request->all(), $rules);
$validate = Validator::make($request->all(), $rules, $customMessage);
if ($validate->fails()) {
return $validate->messages();
}
$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'
]);
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...
}
$validated = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);