Laravel Code Review: Validation Rules, Events, Seeds and Shorter Code

Поділитися
Вставка
  • Опубліковано 20 сер 2024

КОМЕНТАРІ • 37

  • @JustinByrne1337
    @JustinByrne1337 3 роки тому +17

    Thanks Povilas for all the positive feedback. The Seeders were added to the migrations as I was uncertain on how to prevent them from being run multiple times while is on the dev server. I have since realised that I could just use
    php artisan db:seed --class=AllergenSeeder
    for current dev and leave it in the DatabaseSeeder class for new installations

    • @LaravelDaily
      @LaravelDaily  3 роки тому +12

      Also, in all the seeds you could run firstOrCreate() or updateOrCreate() on all records, so if they exist, they wouldn't be created again when seeds are run for the second time, for whatever reason.

    • @pawelpason1501
      @pawelpason1501 3 роки тому +1

      Check doctrine approach. Seeders are overengineering :)

  • @Farishrf
    @Farishrf 3 роки тому +5

    Quick performance tip:
    At 8:20 in line 47.
    It'd be best to take out the count() function from the for loop and put it in a variable.
    because every loop you are executing count() function again.
    It might not make sense In this situation because I assume ingredients aren't that many, but in other scenarios, it might help.

  • @TsA1ex
    @TsA1ex 3 роки тому +6

    At 9:11 you can add second condition inside Gate logic and use only one condition

  • @ryanb509
    @ryanb509 3 роки тому +5

    Unless its on an older version of Laravel before it was a thing, there is a built in rule for the current password called "current_password".

  • @aleksandarstevanovic5854
    @aleksandarstevanovic5854 3 роки тому +5

    well in my opinion, i would use seeder in migrations only if i need data in table right from the start, for example i have "countries" table which doesn't change a lot and i have foreign keys from "addresses" table... other example is "product_states" table i have only new and used records (maybe client will add some more later)... but nicely done factories are a bit better solution for this example... other example is maybe if a client wants a slug and not id in urls, and i don't have "slug" column... so i would make a migration, create a "slug" column in it and right after foreach record fill the column, because i will definitively forget to run seeder on deployment

  • @ryiad2010
    @ryiad2010 10 днів тому

    wonderful review

  • @syedanwarahmedshah3705
    @syedanwarahmedshah3705 3 роки тому

    Thanks sir you are great :) and a gem for laravel devs

  • @patrick-dev
    @patrick-dev 3 роки тому +2

    I believe that Laravel has a default validation rule for checking and validating a given password against the authenticated user's password. I don't see why would he create a custom rule for that.

  • @pawelpason1501
    @pawelpason1501 3 роки тому +3

    Running seeders through migrations is the most correct approach. First of all, in the CD / CI migrations will be started and you will not need to create additional conditions to run when new seeders are created in the application. How you run new seeders on a working application? Manually?
    Second, you can rollback at any time and delete this data if anything goes wrong. By default, seeder mechanism does not provide such an option and creating ex. RemoveUsersSeeder is simply pointless.

    • @JustinByrne1337
      @JustinByrne1337 3 роки тому +1

      The CI/CD is my more recent reason for using the seeder in the migration.

  • @mhyeganeh
    @mhyeganeh 3 роки тому

    That was awesome! 👍 So many thanks

  • @tarekalhalabi8776
    @tarekalhalabi8776 3 роки тому

    Love this videos💙

  • @hassanfazeel2354
    @hassanfazeel2354 3 роки тому

    How to use two arrays in a single foreach loop ?possible?

  • @mahmoudadel8313
    @mahmoudadel8313 3 роки тому

    Can you make video about seo

  • @GergelyCsermely
    @GergelyCsermely 3 роки тому

    Thanks, interesting!

  • @ward7576
    @ward7576 3 роки тому

    I could actually try to send in something for code review, since I haven't gotten a CR from my more knowledgeable peers for like 2-3 solid years lol

    • @LaravelDaily
      @LaravelDaily  3 роки тому

      I currently have a long queue of reviews already, so realistically only in September.

    • @ward7576
      @ward7576 3 роки тому

      @@LaravelDaily Good, they are really good ways to learn. I have done those to juniors I meet at my client companies, they learn quickly and they actually adopt. Sort of the feeling you get when teaching something new to your kid and just being proud about him progressing lol

  • @maxgoose4671
    @maxgoose4671 3 роки тому

    Povilas, greetings! Could you give me an advice, please. When building an API on Laravel, what should i use for editing data on output. Eloquent Mutators or API Resources?

    • @LaravelDaily
      @LaravelDaily  3 роки тому +1

      API Resources: laravel.com/docs/8.x/eloquent-resources

  • @TsA1ex
    @TsA1ex 3 роки тому +1

    New bad fast refactoring. At 8:03 you lost 'adults' and 'kids' values if checkbox not checked. Because there is request->has

    • @LaravelDaily
      @LaravelDaily  3 роки тому +2

      Good catch, should have noticed that one. Need to be more careful in the future.

    • @bumblebity2902
      @bumblebity2902 3 роки тому +1

      Maybe use setAttributes function, if it is need to pass checkbox values.

  •  3 роки тому

    ua-cam.com/video/qyJ_yZuV5gY/v-deo.html i have question about $recipe->ingriends()->attach()... does it checks in database if hat record exists? if no, what happens if i add custom ID to dropdown or checkbox.

  • @user-vs4sd6lw5e
    @user-vs4sd6lw5e 3 роки тому

    I'm sorry, that my question is not actual for this video, but tell please, how currect in Laravel 8 remove "public" segment from url ?
    Thank you.

    • @ward7576
      @ward7576 3 роки тому

      say it in russian, I can re-translate so it's understandable much better.

    • @maxgoose4671
      @maxgoose4671 3 роки тому

      Ты на хостинге чтоль используешь? И, если да, то на каком?

    • @user-vs4sd6lw5e
      @user-vs4sd6lw5e 3 роки тому

      @@ward7576 Поставил laravel 8 на Open Server для локальной разработки и не могу найти мануал как правильно в 8й версии удалить сегмент "public" из url.

    • @user-vs4sd6lw5e
      @user-vs4sd6lw5e 3 роки тому

      @@maxgoose4671 Пока поставил только на локальный вебсервер (Open Server)

    • @maxgoose4671
      @maxgoose4671 3 роки тому

      @@user-vs4sd6lw5e Сари в чем дело то. Как бы, папка бублик ваще не должна быть в урл. Я так понял, у тебя http:127.0.0.1:8000/public/mypage только открывает? Или как?
      Скинь урл.