Junior Code Review: Try-Catch and DB Transactions

Поделиться
HTML-код
  • Опубликовано: 29 июл 2024
  • Another Laravel code review, discussing two topics related to the same problem: overengineering.
    Related videos:
    - Laravel DB Transactions: Example When/How to Use Them • Laravel DB Transaction...
    - Laravel DB Transactions: Rollback on Error [Registration Example] • Laravel DB Transaction...
    CRUD-based reviews:
    - Junior Code Review: Cleaning Up Laravel CRUD • Junior Code Review: Cl...
    - Junior Code Review: 5 Routes into Resource CRUD Controller • Junior Code Review: 5 ...
    - Junior Laravel CRUD+jQuery Code Review: Random Tips in 10 Minutes • Junior Laravel CRUD+jQ...
    - - - - -
    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
  • ХоббиХобби

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

  • @islandblaze007
    @islandblaze007 3 года назад +34

    Why is this channel not more popular? All of his content is first class and addresses real world issues!

  • @holiqibrahim
    @holiqibrahim 3 года назад +9

    In my opinion only channel here discusses laravel functions in detail, thank you

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

    Like this codereview format. Keep it going.

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

    Hi!! Thank you so much for your videos, very simple, helpfull and comprensive, from Chile 🇨🇱!!

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

    Bro! I have a year using laravel to créate my projects and your content have been so greate! Thanks

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

    There is one example where wrapping a simple insert in a transaction could be useful: you can specify a second parameter which allows you to automatically retry the transaction in case it fails due to a deadlock or similar issue.

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

    here I am, one of those juniors lol
    thanks a lot for the advice!

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

    Very useful, thank you Mr.

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

    Great job, Povilas!

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

    In first example we don't see a context of this save method on that model. This method could be overriden inside model with some additional sql inserts/updates/deletes.
    No need to use Carbon::parse, when in model u add date to model property $dates. Same to message attribute - we can use mutator inside model for this. Finally I would prefer using create method over save - sth like Contact::create($request->validated()), but in this case model property $fillable should be added to model with specific fields to save.

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

    Was waiting for it

  • @UsmanAli-yv6vo
    @UsmanAli-yv6vo 3 года назад

    awesome video as always

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

    1:56 also PDOException when saving

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

    Thank you for your great content , can you please talk about composed primary key and how we can use them in laravel

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

    This is great review, I love to see more like this, real case in programming world.
    May we have big code project review, like from route -> middleware -> service provider -> controller

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

      There are so many topics and sub-topics for bigger project code reviews, that it wouldn't fit in my 5-10 minute video format on this channel.
      What exactly is the PROBLEM or QUESTION that you want to be discussed? How to use Service providers? Middleware? What is exactly unclear to you? Then I may narrow it down to specific video(s)

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

      @@LaravelDaily Like, how to create Laravel project using its features so the apps will become more powerful and secure. maybe something like "Laravel apps structure pattern" ???
      Sorry for my bad English, hope you understand what I mean :)

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

      I have a separate long 4-hour course for this :) laraveldaily.teachable.com/p/how-to-structure-laravel-project
      But, remember, there's no ONE way, or even no FEW ways to structure the code. Especially in Laravel, as it's so flexible, you can find dozens of patterns, and all of them will be correct for THEM.

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

    I feel if validation is properly done most times db transaction is not necessary.. thats my personal opinion, i use db transaction when i deal with relationship in case a model is deleted while the code is executed... Maybe yo do a tutorial on database concurrency in laravel.. thanks

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

    So amazing, your review are soo good sir. It Just im not understand laravel. I only understand python-django. But still your code review are good

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

    thank you...

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

    Thanks

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

    Awesome

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

    Thanks for this video, do you have any video's on a multi-tenant laravel application (each customer has their own database and you switch based on who is logged in)?
    This could be a nice topic as a video. I personally would like to see how this would all interact with jobs/queues etc...

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

      Not a very deep, but a short review of such project: ruclips.net/video/8ot9IiGaqhk/видео.html

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

    sir i asked question what is the feature of bootstrap with laravel because laravel use taliwind css framework in laravel 8 jetstream

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

    terima kasih

  • @HadToChangeMyName_YoutubeSucks

    I always use try/catch/finally for database actions, always. Even a simple transaction like saving a record in a single table can go foul and if it does I want to catch and handle it, I send alerts to the database and use webhooks to send myself a message that something went foul as well. Because I always use ajax to send data and get a return I always use finally so I can let the client app know that things went well or foul to let the user know. I write administrative software for our company and it's a standing joke that when something goes foul I'm going to be at your desk before you've had a chance to close the "an error occurred saving your data" alert. I work with code that was written 18 years ago by someone who was just learning to program so it's still full of really junk spaghetti code and terrible sql, and because there's so much of it I can't rebuild it all I've taken the trouble to go out and wrap entire functions in try/catch/finally just so I know when something goes wrong until I can get to rebuild it. Some of these functions are actually over 3000 lines long and just a mess of if statements and sql that's concatenated one variable at a time into a string before being executed with simple mysqli pass through executes, and while I rebuild as many as I can get to I also have to be constantly adding new functionality, so rebuilding existing code is a downtime effort. As far as transactions for a single row that makes no sense, if it fails there's nothing to roll back

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

    hi sir any tutorials of implementing event sourcing in laravel application. thanks

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

    I always look forward to when you say the words "Hello Guys", "Posts" and "Request". That sounds so nice! 😊
    Is there any way to send you my code or is there somewhere to apply? :)

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

      You can send me the code via email povilas@laraveldaily.com and/or invite me to Github, username PovilasKorop
      But I don't do "general" code reviews anymore, you need to have some topic or question which would make a good video for RUclips, on that topic.

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

    Thank you a lot for your greate job.Can you tell me what is the color scheme used in your phpstorm?

  • @user-pb6ur2pp3o
    @user-pb6ur2pp3o 3 года назад

    Благодарю

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

    4:14 i think it should keep that transaction. for something like model events or model observers.

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

    how in try catch data insert update i use orm

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

    Do you post requests on topic somewhere so that people can send in their code specific to that topic?

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

      I haven't done it before, but I think I will start doing it. First attempt I've done on Twitter, a few days ago: twitter.com/PovilasKorop/status/1374773763007512576
      And will have a video on that topic.
      Do you have any other suggestions for topics?

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

    What if request doesn't have 'email' ? There is no validation for email, but Contact use $request->emal

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

    Can anyone tell us what is name of this theme on phpstorm?

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

    no no... in my opinion even redirecting back was too good... they should have straight up logged the user out from the system

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

    Net Core snob here. PHP SUCKS! Kappa
    Everyone use they language they prefer and want, I don't care.

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

    The single biggest mistake here is that there is business logic and data being processed in a controller.