laravel image validation
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
laravel image validation
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
email validation in laravel
'email' => 'required|email|unique:users,email',
//@sujay
if any error in blade laravel
@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
@endif
validation in laravel
enum
'priority' => ['required', 'in:normal,meduim,high'],
integer
'department_id' => 'required|integer',
string
'email' => 'required|email|unique:users',
'title' => ['required', 'min:3'],
'name' => 'required|max:120',
integer
'phone' => 'required|regex:/(01)[0-9]{9}/'
'phone' => 'required|numeric|phone_number|size:11'
'PHONE' => 'required|regex:/(0)[0-9]/|not_regex:/[a-z]/|min:9',
From Laravel 5.5 on you can use an artisan command to create a new Rule which you can code regarding your requirements to decide whether it passes or fail.
Ej: php artisan make:rule PhoneNumber
Then edit app/Rules/PhoneNumber.php, on method passes
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return preg_match('%^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$%i', $value) && strlen($value) >= 10;
}
use App\Rules\PhoneNumber;
$request->validate([
'name' => ['required', new PhoneNumber],
]);
create form request laravel
php artisan make:request StoreBlogPost
laravel form validation
php artisan make:controller ValidationController --plain
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us