Laravel Contracts and PHP Interfaces: Explained with Two Examples

preview_player
Показать описание
Interfaces are one of the most confusing topics in OOP with Laravel. When/how specifically should they be used? Let's take a look at two examples.

Related links:

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

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

thelostrider
Автор

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.

dclindner
Автор

thank you for the best explanation about contracts in laravel.

linkernetir
Автор

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

ajithlal
Автор

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

flashandrew
Автор

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.

VadimBesedin
Автор

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

vivekwah
Автор

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.

eduardoromao
Автор

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

L-A-O-S
Автор

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?

freeidol
Автор

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

damilaresamuelfagbenro
Автор

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

soniablanche
Автор

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.

Jagdish
Автор

basically, php is like java in this regards

glowiever
Автор

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

Laflamablanca