Laravel Validation: 12 Less-Known Tips in 13 Minutes
HTML-код
- Опубликовано: 5 июл 2024
- In this video, I'm sharing some more rarely used tips about Laravel validation that I learned over my 5+ years with Laravel.
00:00 Intro
00:53 Tip 1. Required / Present / Filled
02:05 Tip 2. Required_with and Similar
03:06 Tip 3. Rules min/max for Numbers
03:48 Tip 4. Image Dimensions Validation
04:27 Tip 5. Date before Today/Yesterday
05:32 Tip 6. Separators, Arrays, Custom Rules
06:45 Tip 7. Component in Breeze/Jetstream
07:31 Tip 8. Change Error Messages
08:37 Tip 9. Change field Name in Errors
09:15 Tip 10. $request-all() Security Issue
10:45 Tip 11. Customize Form Request Default
12:00 Tip 12. Customize Error Pages
- - - - -
Support the channel by checking out our products:
- Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
- Enroll in my Laravel courses: laraveldaily.teachable.com
- Purchase my Livewire Kit: livewirekit.com
- Subscribe to my weekly newsletter: bit.ly/laravel-newsletter - Хобби
You are my daily snack of knowledge. Nom nom nom!
Povilas, I can't get enough of saying this: your work helps me to improve as a Laravel developer. Thank you very much.
Tamo junto Cláudio
This Chanel is the best Chanel in Laravel...
Thanks, Mr. Pvilas
After busy week, I was behind in 5 videos , now I'm uptodate xD
Excellent, Thanks a lot for your time and efforts
You are the best! Best channel on Laravel. A lot of knowledge. Thank you
TBH, from this superb helpful video I learned a lot! Specially I never knew something like Fake Filler extension ever existed. It's really saving my time and improving my productivity.
Thanks Dear Povilas 🧡
I learned again a lot. Keep doing :) Thank You!
Thanks surely we must support you by buying your products. :)
Much appreciated!
Thanks for sharing, great video as always.
Thank you very very much
Thank you Povilas!
i've learned a lot!
Thanks as always!
You deserve big thanks, Thank you Povilas
Poop-ton of useful information in this video. Thanks for all the great content, really appreciate it
Thank you so much ,
you are so amaizing
Thanks for this video sir..
Thank You very much :)
Try to use laravel validate and catch error in case file is bigger than upload_max_size or post_max_size!
This is awesome :)
Custom validation error messages tip was really an eye-opener for me 😅 I thought I'd have to do manual validation to accommodate the client's required messages in three different languages 😬
Great.. I didnt know "present" rule.. Amazing
Bail in validation is very helpful
thank you , you are amazing
really helpful
Superb!
Awesome!
thank you...
Hi ..
this is the best channel I've ever seen ..
do you have any courses on the internet ? ..
THANKS
A lot of them, actually, go here: laraveldaily.teachable.com
Hi to everyone! There is a way to validate a two fields unique combination? I'm in a project which need to validate a combination of slug and category (The user can choose the slug in the form) in order to avoid duplicated urls. Thanks in advance
Sir, please reply.
One of my senior told me to use validations inside MODELS, but in Laravel, I generally use FORM-REQUESTS to validate data (I use the same form request for API and WEB requests), he a developer in some other language and told me that, if you will use validations in MODELS, you will not need to write separately validate request in API, SEEDERS, CONTROLLERS etc, you can use the model validation just from one place, check the validation at boot function while self::creating.
So that anyone who tries to create any data using that model, validation must pass.
What you think about this approach.
I have issue with sometimes rule. I don't present any value to password and I get validation error rule, although it should trigger if I present some value.
Thank you for sharing. I validate phone number using this method 'digits:10'. What you are using?
For phone numbers, there are special validation libraries depending on the country: blog.quickadminpanel.com/phone-field-validation-with-laravel-phone-package/
I would advise to NOT validate it like digits, cause there are different formats to write a phone number, like (+370) 611 23566
@@LaravelDaily Thank you. It's very usefull. I will try it on my projects. But in this case it is just 10 digital number because it a local project, and only mobile number is needed.
You can get validated data not only from FormRequest. Simply do - $data = request()->validate([/*rules*/]); And in $data variable will be ONLY validated fields.
It is usefull if you have unique validation rules in one place in your code
If u do that u dont use SOLID principles
@@igerardogc Yeap. But in video Povilas said that is no way to do that. I shoed that it's possible
Hello Sir,
Can I used bootstrap instead of Tailwind in Jetstream ?
If yes then how can used it.
Yes, with Jetstrap: ruclips.net/video/Pd7EF2rkyOM/видео.html
question on $request->validated() 10:04
I tried it once and it didn't work.
I then found out that the issue was that the Form Field "name" was different from the "Database Table" column name.
So is there a way "out of the box" with Laravel to have the form field name="user_name" while the database table column name can be "name" and still make this work?
In form request class you can manipulate with prepareForValidation()
How can I use the age minimum restriction with a date field?
Something like a (date now - filled date) >= 18, or is there a better way.
Something like "before:" . now()->subYears(18)->toDateString()
@@LaravelDaily thanks!
@@LaravelDaily Sorry to bother you again but I have my laravel app translated on Middleware level, so on request it checks for the browser language or api accept language header.
But the :date placeholder value from my translation file is not localized in the error message.
My browser asks for day month year but the error says must be before year month date (in Dutch), witch is confusing for users. Where can I change this behavior?
I don't want to confuse English speakers either by hard-coding it the other way like you wrote in your blog article.
Sir i have a question that how we validate unique email when we want to update user.
Rule::unique('users')->ignore($user->id)
Sir, how to make unique validation of 2 or 3 fields in controller. ?
So when inputting the same data on 2 or 3 fields a notification will appear that the inputted data already exists.
I would create a custom validation rule for this.
@@LaravelDaily do you have example video for this.
On custom rules, yes: ruclips.net/video/K-uvIn-4Ug0/видео.html
@@LaravelDaily thanks sir.
Nice 👌
Tip 10 and 11 title not shown in video
Hm, interesting, will be more careful editing next time.
Hi. Offtopic. How to return response json from Request Form ?
Better then $request->validated() is to use DTO but it doesn't means that validation is not required.
can i use $request->validated() without form request? i use $request->validate() can i do with this method?
Yes
@@LaravelDaily how exactly i use this, any refrence will be great. Thanks
hi ,Povilas i need one vedio clip on user authentication with firebase and messaging with firebase..when you uplode this vedio?
Firebase is not in the near plans, sorry
When you made that clip?
Validated function is available in Validator::make!!!!
Hello Sir,
I want to Validate One User Name... It may Either Email or Phone... I have two Regex... How to put OR condition in Laravel Validation...
Thanks in Advance.
If you have two regexes, probably you combine them into one regex?
@@LaravelDaily
Thank you so much for your Reply.
can you just write __('Name is required') ?
your explanation is not complicated and simple to be understood
3:18 just another developer creating 18+ websites