Laravel Contracts and PHP Interfaces: Explained with Two Examples

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 พ.ย. 2024

ความคิดเห็น • 40

  • @thelostrider1
    @thelostrider1 3 ปีที่แล้ว +14

    Nice video. When using Laravel people seem to forget that Laravel is PHP and end up don't learning OOP or "pure PHP" (mostly because it's kinda easy to use Laravel without much knowledge of PHP). That's something I don't like, even tho I'm learning Laravel I feel the need to learn more about pure PHP and OOP in general

  • @dclindner
    @dclindner 3 ปีที่แล้ว +10

    Given PHP's limit of extending from only one class, you can't rely on on abstract class, necessarily, if you're providing code to be used by others (such as open source packages). it seems common to define an interface with the methods required, and include a trait that defines those methods. I found this confusing at first, but very helpful to add functionality while working around the one-class extends limit.

  • @linkernetir
    @linkernetir ปีที่แล้ว

    thank you for the best explanation about contracts in laravel.

  • @ajithlal1688
    @ajithlal1688 3 ปีที่แล้ว +1

    I was struggling to understand interface and this video gave me a better understanding. Thank you ❤️

    • @L-A-O-S
      @L-A-O-S 3 ปีที่แล้ว +1

      There are still abstract classes awaiting you, which will only create more confusion. )

  • @VadimBesedin
    @VadimBesedin 3 ปีที่แล้ว +9

    So, as i understand, interface would be good for situation when i need to process payment. One interface and several payment provider classes will be implementing that interface. Also later i will be able to add just another payment provider class and it will work with present interface. Right?
    It's like USB, you can connect different devices to it, and they will work normally because they implement this USB interface.

  • @flashandrew6772
    @flashandrew6772 3 ปีที่แล้ว +4

    Thanks for the video! It also can be great to see some videos like “middle” level of difficulty. For example something about compare ORM and CQRS. Or maybe some explanation about concepts of DDD

    • @lucasj.pereira4912
      @lucasj.pereira4912 3 ปีที่แล้ว +2

      Also websockets

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +3

      For now, I'm focused on practical topics and not theoretical concept comparison. Maybe, when I run out of practical topics, I'll switch to the philosophy on this channel :)

  • @lma_cristian
    @lma_cristian ปีที่แล้ว

    Now I understand it better.

  • @itone3438
    @itone3438 2 ปีที่แล้ว +1

    thanks

  • @vivekwah
    @vivekwah 3 ปีที่แล้ว +6

    I always have trouble deciding to use either interface or abstract class. Can you please help with this confusion.

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +8

      Ok adding the interface and abstract classes to the to-do list.

    • @igoreksazonov
      @igoreksazonov 3 ปีที่แล้ว

      its up to your mind

    • @vivekwah
      @vivekwah 3 ปีที่แล้ว +1

      @@igoreksazonov yes till now I have been using with that mindset only. But in some good repos I've noticed in some places abstract classes are used and some places interfaces. I only have difference with respect to inheritance. Using abstract class we restrict extend with that class whereas in case of interface there can be many interfaces implemented.

    • @kaczuszka-dt
      @kaczuszka-dt 3 ปีที่แล้ว +5

      Abstract classes do offer some functionality, its not just structure, its the actual functionality with something in already.
      Interfaces offer only and only description of what the class should be capable of, we cannot give it any real properties or functionality, just a shared set of methods

  • @deveshmaurya9101
    @deveshmaurya9101 2 ปีที่แล้ว

    Thanks for posting

  • @eduardoromao
    @eduardoromao ปีที่แล้ว

    Can be named “API”. Its more natural above Interface and Contract.
    API provides a contract for another service. So contract and API is the same thing, but i’m below API term is already used in hardware and software like a standard, not needing new term like contract.

  • @haroldpepete
    @haroldpepete 3 ปีที่แล้ว

    Thank sr for share

  • @sale7680
    @sale7680 2 ปีที่แล้ว

    Thank u 🙏

  • @pasizdobrekuce
    @pasizdobrekuce ปีที่แล้ว

    Dependency inversion FTW. 🙌

  • @L-A-O-S
    @L-A-O-S 3 ปีที่แล้ว +1

    Oh, OOP is already here) Cool, well then you should take into account that there are also abstract classes. It's just difficult to rebuild your logic in order to start using all this, although the advantages are immediately felt. And looks like interfaces should be named like gates or politicians? liked the topic of using oop in laravel

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      Ok adding the interface and abstract classes to the to-do list.

    • @Bevallalom
      @Bevallalom 3 ปีที่แล้ว

      Laravel is PHP OOP mostly..... Just saying.

  • @damilaresamuelfagbenro1881
    @damilaresamuelfagbenro1881 2 ปีที่แล้ว

    I have got a question. Is it possible to have the CanCaptureScreenshot binding with both classes in the service provider?

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว

      Why would you need that? How would Laravel then know which class to run?

  • @msdeav
    @msdeav 3 ปีที่แล้ว

    thank you, sir..

  • @free2idol1
    @free2idol1 ปีที่แล้ว

    I noticed that the author used this function to name his file: $filename = uniqid().'_'.Str::random(30) . ".png";
    => if you loop through 10 files and using above function to name your file, is there any chance that you would get duplicate file name?

  • @jailsoncarneiro4936
    @jailsoncarneiro4936 2 ปีที่แล้ว

    Show de Bola!

  • @Jagdish0724
    @Jagdish0724 3 ปีที่แล้ว

    User hasMany(cities)
    City hasMany(Users), hasMany(Restaurants)
    Restaurants belongsTo(City)
    Orders belongsTo(Restaurants)
    now there are city wise admins. admins can see orders of their assigned cities only with global scopes to other cities records .
    How to create this relationships.

  • @aymenmohammed2625
    @aymenmohammed2625 3 ปีที่แล้ว

    ❤😍

  • @glowiever
    @glowiever 2 ปีที่แล้ว

    basically, php is like java in this regards

    • @fangfang3366
      @fangfang3366 ปีที่แล้ว

      We should say both of them follow OOP, even like c# LOL

  • @soniablanche5672
    @soniablanche5672 3 ปีที่แล้ว +1

    interface is the opposite of trait, instead of being provided with methods you have to implement them yourself.

  • @Laflamablanca969
    @Laflamablanca969 3 ปีที่แล้ว +5

    The interface for the relationship is pointless. It’s just adding more complexity than is needed.

  • @devrajin5795
    @devrajin5795 3 ปีที่แล้ว

    first viewer :D

    • @L-A-O-S
      @L-A-O-S 3 ปีที่แล้ว

      Firster then video duration)