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
  • ХоббиХобби

Комментарии • 76

  • @fahnleindieselschweif5022
    @fahnleindieselschweif5022 3 года назад +12

    You are my daily snack of knowledge. Nom nom nom!

  • @Claudio_Pereira
    @Claudio_Pereira 3 года назад +25

    Povilas, I can't get enough of saying this: your work helps me to improve as a Laravel developer. Thank you very much.

  • @alila3883
    @alila3883 3 года назад +4

    This Chanel is the best Chanel in Laravel...
    Thanks, Mr. Pvilas

  • @Somcoders
    @Somcoders 3 года назад +3

    After busy week, I was behind in 5 videos , now I'm uptodate xD

  • @Babaknouri
    @Babaknouri Год назад

    Excellent, Thanks a lot for your time and efforts

  • @niamreg_dev
    @niamreg_dev 3 года назад

    You are the best! Best channel on Laravel. A lot of knowledge. Thank you

  • @alnahian2003
    @alnahian2003 Год назад

    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 🧡

  • @GergelyCsermely
    @GergelyCsermely 3 года назад +5

    I learned again a lot. Keep doing :) Thank You!

  • @davidson7838
    @davidson7838 3 года назад +2

    Thanks surely we must support you by buying your products. :)

  • @hatsushiroyuki8697
    @hatsushiroyuki8697 3 года назад +1

    Thanks for sharing, great video as always.

  • @MahmoudIsmail-en3nu
    @MahmoudIsmail-en3nu 2 месяца назад

    Thank you very very much

  • @ArthurMoraisDev
    @ArthurMoraisDev 3 года назад +2

    Thank you Povilas!
    i've learned a lot!

  • @belce1982
    @belce1982 2 года назад

    Thanks as always!

  • @ridamakhchan
    @ridamakhchan 3 года назад

    You deserve big thanks, Thank you Povilas

  • @cloudergnu
    @cloudergnu 3 года назад

    Poop-ton of useful information in this video. Thanks for all the great content, really appreciate it

  • @programminggeekseth3797
    @programminggeekseth3797 Год назад

    Thank you so much ,
    you are so amaizing

  • @ashwanisingh9283
    @ashwanisingh9283 3 года назад +1

    Thanks for this video sir..

  • @salimedia33
    @salimedia33 3 года назад +1

    Thank You very much :)

  • @margop3567
    @margop3567 2 года назад +1

    Try to use laravel validate and catch error in case file is bigger than upload_max_size or post_max_size!

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 3 года назад +1

    This is awesome :)

  • @rashidrumman871
    @rashidrumman871 3 года назад

    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 😬

  • @surflaweb
    @surflaweb 3 года назад

    Great.. I didnt know "present" rule.. Amazing

  • @nadeemahmed7947
    @nadeemahmed7947 3 года назад

    Bail in validation is very helpful

  • @a-ezzat5677
    @a-ezzat5677 3 года назад

    thank you , you are amazing

  • @AbrarAhmad-mz8vl
    @AbrarAhmad-mz8vl 3 года назад

    really helpful

  • @waqasmushtaq81
    @waqasmushtaq81 3 года назад

    Superb!

  • @nhantran3472
    @nhantran3472 3 года назад

    Awesome!

  • @msdeav
    @msdeav 2 года назад

    thank you...

  • @mibrahim4245
    @mibrahim4245 Год назад

    Hi ..
    this is the best channel I've ever seen ..
    do you have any courses on the internet ? ..
    THANKS

    • @LaravelDaily
      @LaravelDaily  Год назад +1

      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

  • @randomguy5922
    @randomguy5922 3 года назад

    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.

  • @bumblebity2902
    @bumblebity2902 3 года назад

    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.

  • @debjit21
    @debjit21 3 года назад +2

    Thank you for sharing. I validate phone number using this method 'digits:10'. What you are using?

    • @LaravelDaily
      @LaravelDaily  3 года назад +2

      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

    • @debjit21
      @debjit21 3 года назад

      @@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.

  • @infureal
    @infureal 3 года назад +1

    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

    • @igerardogc
      @igerardogc 3 года назад

      If u do that u dont use SOLID principles

    • @infureal
      @infureal 3 года назад +1

      @@igerardogc Yeap. But in video Povilas said that is no way to do that. I shoed that it's possible

  • @JaswinderSingh-cb4by
    @JaswinderSingh-cb4by 3 года назад +1

    Hello Sir,
    Can I used bootstrap instead of Tailwind in Jetstream ?
    If yes then how can used it.

    • @LaravelDaily
      @LaravelDaily  3 года назад +1

      Yes, with Jetstrap: ruclips.net/video/Pd7EF2rkyOM/видео.html

  • @shadowsurounds
    @shadowsurounds 11 месяцев назад

    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?

    • @LaravelDaily
      @LaravelDaily  11 месяцев назад +1

      In form request class you can manipulate with prepareForValidation()

  • @Stoney_Eagle
    @Stoney_Eagle 3 года назад

    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.

    • @LaravelDaily
      @LaravelDaily  3 года назад +1

      Something like "before:" . now()->subYears(18)->toDateString()

    • @Stoney_Eagle
      @Stoney_Eagle 3 года назад

      @@LaravelDaily thanks!

    • @Stoney_Eagle
      @Stoney_Eagle 3 года назад

      @@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.

  • @NotBeHaris
    @NotBeHaris 3 года назад

    Sir i have a question that how we validate unique email when we want to update user.

  • @blokkaliwon7794
    @blokkaliwon7794 2 года назад

    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.

    • @LaravelDaily
      @LaravelDaily  2 года назад

      I would create a custom validation rule for this.

    • @blokkaliwon7794
      @blokkaliwon7794 2 года назад

      @@LaravelDaily do you have example video for this.

    • @LaravelDaily
      @LaravelDaily  2 года назад

      On custom rules, yes: ruclips.net/video/K-uvIn-4Ug0/видео.html

    • @blokkaliwon7794
      @blokkaliwon7794 2 года назад

      @@LaravelDaily thanks sir.

  • @alimahdavi9775
    @alimahdavi9775 3 года назад

    Nice 👌
    Tip 10 and 11 title not shown in video

    • @LaravelDaily
      @LaravelDaily  3 года назад

      Hm, interesting, will be more careful editing next time.

  • @mindaugasvirbickis4061
    @mindaugasvirbickis4061 3 года назад

    Hi. Offtopic. How to return response json from Request Form ?

  • @guramikutivadze
    @guramikutivadze 3 года назад

    Better then $request->validated() is to use DTO but it doesn't means that validation is not required.

  • @rizkihutama5633
    @rizkihutama5633 3 года назад

    can i use $request->validated() without form request? i use $request->validate() can i do with this method?

    • @LaravelDaily
      @LaravelDaily  3 года назад +1

      Yes

    • @rizkihutama5633
      @rizkihutama5633 3 года назад

      @@LaravelDaily how exactly i use this, any refrence will be great. Thanks

  • @muhammadfarhanahmed9280
    @muhammadfarhanahmed9280 3 года назад

    hi ,Povilas i need one vedio clip on user authentication with firebase and messaging with firebase..when you uplode this vedio?

  • @morte226
    @morte226 3 года назад

    Validated function is available in Validator::make!!!!

  • @shubhajeet10
    @shubhajeet10 2 года назад

    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.

    • @LaravelDaily
      @LaravelDaily  2 года назад +1

      If you have two regexes, probably you combine them into one regex?

    • @shubhajeet10
      @shubhajeet10 2 года назад

      @@LaravelDaily
      Thank you so much for your Reply.

  • @raimonds.L
    @raimonds.L 3 года назад

    can you just write __('Name is required') ?

  • @a-ezzat5677
    @a-ezzat5677 3 года назад +1

    your explanation is not complicated and simple to be understood

  • @joaocagnoni1
    @joaocagnoni1 3 года назад +1

    3:18 just another developer creating 18+ websites