https://github.com/saip13/laravel-validations
Laravel validations
https://github.com/saip13/laravel-validations
backend-validation form formvalidation laravel php validation-errors validations validator
Last synced: about 1 month ago
JSON representation
Laravel validations
- Host: GitHub
- URL: https://github.com/saip13/laravel-validations
- Owner: SaiP13
- Created: 2021-12-06T09:56:11.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-25T12:08:43.000Z (about 4 years ago)
- Last Synced: 2025-07-04T15:36:22.225Z (11 months ago)
- Topics: backend-validation, form, formvalidation, laravel, php, validation-errors, validations, validator
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# laravel-validations
use Illuminate\Support\Facades\Validator;
use Validator;
### # USING ARRAY:
$validatedData = $request->validate([
'title' => ['required', 'unique:posts', 'max:255'],
'body' => ['required'],
]);
### #Normal | :
$validated = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
'name' => 'unique:posts',
'start_date' => 'required|date',
'email' => 'email',
'size' => 'max:10|min:3',
'title' => 'size:12', //exactly 12 character long
'tags' => 'array|size:5', //array size 5
'image' => 'file|size:512', //exactly 512 kilobytes
'photo' => 'mimes:jpg,bmp,png', //file types
'avatar' => 'dimensions:min_width=100,min_height=200',
'password'=> 'required|confirmed' //match with confirm_password field
]);
### # THIS:
Automatically control returns back if validate errors occurs
$this->validate($request, [
'name' => 'required|unique:users',
'mobile' => 'required|size:10',
'email' => 'required|email'
]);
### # USING VALIDATOR:
$validator = Validator::make($request->all(),[
'name' => 'required',
'mobile' => 'required',
'email' => 'required'
]);
if($validator->fails()){
return response($validator->messages(), 200);
return response($validator->errors(), 200);
}
### #CUSTOME MESSAGES:
$validator = Validator::make($request->all(), [
'type_id' => 'required',
'seller_id' => 'required',
'name' => 'required',
'product_id' => 'required',
],
[
'type_id.required' => 'This field cant not be blank',
'seller_id.required' => 'seller ID can not be blank',
'name.required' => 'Name can not be blank',
'product_id' => 'Product ID must be enter'
]);
### #PRINT ERROR MESSAGES:
1) $errors->all()
2) $errors->get('field_name')
3) $errors->first('field_name')
4) $errors->has('email')
5) @error('email')
6) $message
### #All:
@foreach ($errors->all() as $error)
@endforeach
### #Single error:
@error('title')
@enderror
### #if cond:
if ($errors->has('email')) {
{{ $errors->first('email'); || $errors->get('email') }}
}