Database Transactions - Automatically Rollback If Something Goes Wrong - Laravel

Поделиться
HTML-код
  • Опубликовано: 5 фев 2022
  • In this video, we will be looking at how to automatically roll back the database code that has been already executed when something goes wrong. We can make use of database transactions to roll back the changes when something goes wrong. Also there are some things that you need to do when using queues with database transaction. This video will show you in detail about this.
    === Important Links ===
    Fonts, extensions I use, and Support Laratips links:
    bit.ly/m/laratips
    ====================== Support ======================
    If you want me to continue making this kind of video for free on RUclips, then you can help me financially by sending a few bucks to my Wise (wise.com/invite/u/ashishd233) account in Nepalese 🇳🇵 currency.
    My Wise email: ashish.dhamala2015@gmail.com
    If you decide to support me, please send me your Twitter handle in the mail so that I can shout out about you.
    ====================== Social Media Links ======================
    Let's be friends
    / aashish_dhamala
    ====================== Video Related Links ======================
    Database transaction documentation link:
    laravel.com/docs/8.x/database...
    ====================== Other Videos ======================
    Laravel Package Development Playlist
    • Laravel Package Develo...
    Password Validation In Laravel with at least one Letters, Numbers, Upper and Lowercase or Symbols:
    • Password Validation In...
    Multiple Apis With ForwardsCalls Trait And Code Refactoring Tip - Laravel Hidden Feature:
    • Multiple Apis With For...
    Laravel Chunking - You Might Be Doing This Wrong - Problem and Solution:
    • Laravel Chunking - You...
    Laravel Tip - Properly Get Data Between Two Dates
    • Laravel Tip - Properly...
    Get Data From Multiple Databases In One Project | Laravel Tip
    • Get Data From Multiple...
    ========= Theme and Font Used =========
    Theme:
    Cobalt2 Theme Official (marketplace.visualstudio.com/...)
    Font:
    JetBrains Mono (www.jetbrains.com/lp/mono/)
    ====================== Tech stack ======================
    Laravel
    PHP
    #laravel #php #laraveltip #laratips

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

  • @sanjeetsagar
    @sanjeetsagar 2 года назад +2

    Really informative
    Thanks for sharing.

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

    Great, thank you!.

  • @mosharrafhossain2962
    @mosharrafhossain2962 9 месяцев назад

    nice explaination boss

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

    Very informative bro, Keep it up 🤗

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

    Great Video Sir

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

    Nice content as always. Very informative. My question is even if the mail is not queued can afterCommit still stop the sending of mail if error occurs?

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

      I am mot sure about that. Need to check.

  • @dhanushj.a420
    @dhanushj.a420 5 месяцев назад

    Nice tutorial. I'm new subscriber

  • @md.anwarhossain1179
    @md.anwarhossain1179 2 года назад

    It’s really helpful.
    Dear, please make a video which are changes in Laravel 9.❤️❤️

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

    Thanks

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

    Thank you !
    How to proceed if some database insertion is performed in an external service class ? Is there a way to "queue" insertion ?

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

      It doesn't matter where the database insertion is happening. As long as it's inside database transaction, it will get rolled back.
      I would recommend not to write DB::transaction inside service class but in controller always. That way you can be consistent.

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

      @@Laratips Ok, but if let's say a Service is responsible for creating roles and permissions, how to proceed ? You send the user transaction to the service inside the DB transaction, and then if permission assignment fails into the service, will the transaction rollback ?

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

      Yes, it will rollback if the service is inside transaction.

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

      @@Laratips Ok thank you very much !

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

    Very interesting. Never used DB Transaction, but I will take into account

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

    Thank you I was not aware about transaction with mail part.
    Can you plz make video on bounce mail and unbounced mail part?

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

      Different mail sending services like mailgun, postmark, etc will have hooks where you can add your application url. And let's say when en email is bounced, they will hit the url that you have specified. And you can easily say the mail as bounced by saving bounced info in the database if this url is hit.

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

    Kudos to your dedication !!! it is awesome

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

    After commit is available in Observers too

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

      Yes, its available in everything that can be queued.