Laravel Services and Repositories: 3 Example Projects

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

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

  • @robertoflores2078
    @robertoflores2078 3 года назад +53

    Services = Business Logic stuff
    Repositories = Database related stuff
    Controllers interact with Services.
    Services interact with Repositories.
    Repositories interact with a Model and its relational Models if neccesary (one-to-many, many-to-many, etc).
    Repositories should not access other Repositories, that kind of logic should be done in a Service.

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

      so i may not call a repository in a controller? would be right: controller -> service -> repo?

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

    Thanks for mentioning my code in 2nd example. And it's not a fully done project yet. I am still doing that project.

  • @SowrenSen
    @SowrenSen 3 года назад +7

    Man your contents are getting richer. 😀

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

    I wish this video came in a couple of weeks earlier. I received a project following that same pattern and it was a little bit hard to understand at first.
    It was really nice to see your explanation and now I’m more confident in the changes I’m making to this project

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

    Awesome stuff, I always get a lot of stuff from your videos.

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

      I used a Service pattern discussed by Povilas in one of the projects I work on, it was really helpful! Needed to duplicate some functionality on different pages.

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

    I remember to avoid TypeHint REQUEST in service via Dependency Injection. Instead just pass Request Array.
    It is useful in TESTs also.
    Respect from Pakistan 🇵🇰

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

      Learned that the hard way.

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

      What i personally prefer that in service you have specified methods iwht actual parameters you want to call. So instead of passing request or some general array you just provide like int, strings etc stuff and other arrays, like only what's needed for a method.

  • @JoseVasquez-vy8yf
    @JoseVasquez-vy8yf 3 года назад +1

    Thanks a lot for sharing examples regarding Services and Repositories, I hope you keep posting more of it because it's really helpful.
    The only thing that seems off to me is the idea of passing the request to the service. I've seen it in cases even reaching to the repository and I don't believe it's a good practice. It makes quite hard to reuse these methods since you don't know which fields the method uses unless you read it thoroughly

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

      The author of the video is fool. This kills the whole point of using the services/usecases. We will not be able to call such service from the API, console application or queue system.

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

      @@anmaner4822 he did a video about not using request on services, so don't call him a fool, cause he did not even say it was good in this video.

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

      ​@@thamibn Are you joking? What's the matter what was in the other videos? In this video he uses function auth()->user(). And now the question, what if he calls this service from console? Everything will break, and how i said above this kills the whole point of using services.

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

      @@anmaner4822 he did not use it his not the one who wrote the code, basically in this video he was showing us how services worka or helps with code readability, he was not by any means trying to fix the code inside those services, if you can check there are many wrong things on those services he demonstrated but the video was not about fixing them instead on how to use them Nd how they help.
      On the other video he clearly thought how to write service classes, and he not to use $request since it won't be accessible when the service is being called on tests,commands etc...
      I do agree that the service classes used on the video where poorly coded, my point is don't call him fool cause is not his code and he was not fixing them service classes on this video.

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

    Really interesting and useful, since Service/Repository is a common pattern also used in other languages, for instance in Java, to build more structured modules (and to make controllers or jobs or whatever much shorter!).
    It’s a very important topic.

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

    You are really superman ❤️🇸🇩 thank you For the grateful lite tutorials. u are helpful please go on don't stop

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

    Thank you for the feedback 👍

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

    When dealing with DB transaction, It should be done in controller or in a service? The service should be throw exceptions and the controller catch it?

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

    Please make a video about PORTO pattern (implemented on apiato project) thanks! Most used architectual patterns for large laravel projects

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

    Respect from 🇯🇲

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

    You mentioned at the end ”To off load your controllers and make controllers shorter” does it mean better performance in controllers? And thats why we use Service? Or is it only for structure and readability?

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

      It's for structure and readability

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

    I am recently learning different design pattern of php. I would be glad to know different design patterns that can be used with laravel beside services.

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

      I discuss a lot of them in my course: laraveldaily.teachable.com/p/how-to-structure-laravel-project

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

    Thank u for the video,Is this good habit making two new instance of a class as seen as 3:15 second of video with Booking class?.May it perform for speed or cpu ?.

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

    Wonder if there are any tests for those services in the examples and if services that have tests are written "better" than the ones that don't have tests.

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

    hello sir .i install jetstream and then i want to extend layouts.app in another file but layouts.app file contain $header and $slot ,so it give $header is not defined or same for $slot.how can then i extend layout.app.
    im using laravel 8 with jetstream livewire

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

    Super! Very useful video.

  • @obelekingsley9224
    @obelekingsley9224 Месяц назад

    I think the service can catch an exception if the purpose is for logging or debugging

  • @Diego-eb9we
    @Diego-eb9we 2 года назад

    Could SpliCostService be a Trait as well?

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

    Hello Dear! Please tell me which framework vue or livewire is good to use with laravel. Should we use vue if our site is too much reactive or livewire would be a good choice in case site is too much reactive.

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

    Very informative!

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

    @3:27 IMO policy inside the StoreBookingRequest would be better to implement the same functionality (availabilityCheck)

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

    Wow this is what I am waiting for

  • @mohamed-haj
    @mohamed-haj 3 года назад +2

    Can you make a vid that explain how to structure your payment services (Paypal, Stripe, local banks ..etc) and use it with a clean code?

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

      That would be a full 5-hour course. Maybe someday I will have enough time for it.

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

    This approach would be nice with Domain Driven Design

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

    how to remove dublicate value from an array while using foreach directive loop in laravel?

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

      Try converting to collection and use unique() laravel.com/docs/8.x/collections#method-unique

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

      @@LaravelDaily thanks you sir, thats working

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

    How can I switch between Paypal / Card Payment / Anything if the binding is with the service provider, if the user has a choice when paying.

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

      Yes, valid question, that example code wouldn't work for your scenario.

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

      You could pass the payment method in request and check that payment in service provider and bind the class according to request payment variable.

  • @al-aminhamadi9451
    @al-aminhamadi9451 3 года назад +1

    Nice stuff

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

    First of all, thank you so much for all your work! What are your thoughts on using Jobs for all CRUD (except Read part) operations?

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

      I quite like Jobs, but not for CRUD operations themselves, but rather AFTER CRUD operation. So, like User::create() and then dispatch a Job to send an email.

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

    So this repository pattern has nothing to do with Symfony repositories?

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

    Respect from 🇹🇿Tz

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

    Please review DataTables and why do we need it :)

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

      I have a full separate course: laraveldaily.teachable.com/p/datatables-in-laravel
      Also, search the channel for "datatables", you will find quite a lot of videos.

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

    Services vs Actions, or is the pattern essentially the same?

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

      I will have a separate video on Actions, in a few days.

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

    Hi Povilas, thanks for the great video with Laravel services patterns reviewal! Just wanted to ask you, have you some preferable PHP and Laravel packages very useful for building API for Laravel based SPA? I'm most interested with the secure authentication/authorisation, flexible roles management, message driven services, multi-tenancy. Probably some of them are already included in the scope of QuickAdminPanel stack. Could you please make a quick review based on your experience, or share some practical advices? Thanks a lot and please don't stop posting new streams! Cheers.

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

      Not sure if there are "best practices", I guess I would list Laravel Sanctum and Spatie Permissions.

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

    You guys have good team why don't you make an ecommerce platform and sale its components just like other doing etc opencart? I don't see any good ecommerce platform in laravel with good documentations. You can easily build opencart like with your capabilities

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

      It would cost too much. And personally, I don't believe in financial success, as there are already ecommerce platforms on Laravel, but none of them seemed to get traction.

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

    hi sir, I had learn a lot from your videos, and even started exploring many concept. sir can you give me way to contact you. need your consultants .

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

    wow terima kasih

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

    Please make laravel from scratch for beginners 🙏🙏🙏🙏🙏

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

      Done: laraveldaily.teachable.com/p/laravel-for-beginners-your-first-project

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

    Respect from Ukraine 🇺🇦

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

    first view first like