SOLID Principles in Laravel: 5 Examples (+ New Course!)
Vložit
- čas přidán 24. 07. 2024
- Get the full course "SOLID Code in Laravel" laraveldaily.com/course/solid...
In this longer video, I will show examples of SOLID principles, specifically in Laravel projects.
00:00 Intro and New Course
01:53 S: Single Responsibility Principle
04:29 O: Open-Closed Principle
07:08 L: Liskov Substitution Principle
11:11 I: Interface Segregation Principle
13:35 D: Dependency Inversion Principle
15:40 SOLID in Everyday Life
- - - - -
Support the channel by checking out our products:
- Enroll in my Laravel courses: laraveldaily.com/courses
- Subscribe to my weekly newsletter: bit.ly/laravel-newsletter - Jak na to + styl
"I'm not in the mood to fix it." Everyone in their programming life has said it at least once!
It's just that I know that I'm in the flow of shooting video, and if I break it to spend 15 minutes on diving into PhpStorm configs, the video quality will get worse when I get back :)
@@LaravelDaily To fix some of the warnings. Instead of doing Model::all() and Model::where() always start with Model::query() i.e. Model::query()->where()
Yes, that may help with some Eloquent methods (also Laravel IDE Helper may help), but in that particular case, it was a general screw up with PhpStorm .idea settings, it didn't recognize even the base Controller in Laravel.
@@LaravelDaily Make a t-shirt with the phrase
In only 21 minutes you're teaching something which looked so difficult and intimidating to me at first, and now I completely understand what SOLID means. You're one hell of a teacher. Thanks for the free content!
The presentation of information is so simple and extensive that you are surprised at the skill of the narrator. True artisan)
I loved the way you explained SOLID. Finally, I can say that I'm starting to understand it.
Kinda Self-taught here! I had lots of duplicate code on my project, in views, controllers, livewire components, etc. Now I'm applying what I've learned from you (services, form requests...) and it makes maintainability and changes so much easier! Thank you all the way from Senegal :D
You are my inspiration of upgrading my coding standards daily. Thank you
Best description of SOLID in Laravel I've seen. Thank you.
Thank you, Povilas! You are perfect simplifier! Even I could not explain those principles in more understandable way.
Thank you. Agree it is not easy to find SOLID examples in PHP with real life examples. Thanks for this and the course.
I love how you explain the code, it really expands my knowledge
I always wanted to learn more about SOLID. Thanks!
Thank you so much. Always awesome learning from your channel. I look forward to making videos as awesome as yours in the near future. For now, i stick with the basic ones lol
Finally you made it easily understandable to me. Thanks a lot!
finally i can understand what is open close principle benefit. the codeis extended, no need to import or send another data to view again. thanks
Loved the "SOLID in Everyday Life" part. Because, we can learn SOLID from different sources. But very few told the thing that you told in this part - The real life dilemma.
We actually need to talk to our future self. And also need to think about the next developer(s) who will work on this code.
You might even say "Sometimes reality gets in the way of our idealism"
Hey Povilas,
Brilliant Content!
Thank you for sharing your knowledge.
I just waiting for that. I was very curious to know how SOLID will work with LARAVEL. Because, I saw that the D of SOLID always break when we write code..
Thanks a lot, sir😍
you really just doing a great explanations in your CZcams channel
Very usefully and easy to understand! Thank you!
Please make a video about Laravel websockets (Pusher). It will be great job!
I will create a full course about it, later in 2021.
Very well explained the information here is pure gold. Thanks for sharing wish I could give 1k likes to the video.
I'm very grateful for your extremely useful videos!
Thanks i’ll enroll your corse shortly
Sir! great effort, its very helpful, thanks.
Best teacher ever. Thank you!
Thanks, I'm happy to leran sometning new again :)
you are my inspiration. please shoot a video on following topics.
1) The common PHP or web server exploits and their solutions.
2) Integration of multiple data sources and databases into one system.
Thanks in advance.
Sorry, those topics are not in plans, too narrow edge topics for my audience.
This is the best explanation I met
Great tutorial as always
Thanks as always!
thank you for this content
Thank you so much 🙏🙏
Хороший английский, превосходное видео!
Спаасибо
great job as usual
Would be interested to see more combining I and D. E.g. if you're separating your interface concerns as you did in your example, but the method typehinting actually requires the combination of those interfaces how would you approach that? Would you have to create another interface which implements the two ones we need and just typehint that? Cheers.
Good question. I guess in that case, if the situation requires one or another class, it would not go into parameter anymore, bue would rather be resolved inside the function itself.
You talked about considering what might change in the future when choosing to implement the SOLID Principles. Doesn't that Violate the YAGN Extreme Programming Principle?
Readable, maintainable and TESTABLE!
I think I need to shoot a separate video on how to make code testable. Thanks for the suggestion, added to the to-do list.
Nice! But how many methods/resposabilities does that controller have?
Excelent! Thank you for all you videos, I'm learning a lot, i have a doubt when you typehint the return type of a function, that function must return something always, if returns null, an exception occurred, and sometimes that null value it's fine, how should I proceed in that case?
You may specify a few types to return: type, null or exception
Thanks!!
Sublime is perfect for showing code
shouldn't ReportDownloadInterface extends ReportDataInterface intead of implementing both?
Thanks for awesome courses. Do you have any plan making a course for Laravel Octane?
No, I haven't used it myself, and not planning to.
Up till now I always treat 1 module in 1 class(ex: for Creating, updating and deleting with bunch of private methods for everything else that shouldn't accessed from outside the class for example for repeating task inside the class) until my team ask me to implement single responsibility principle and I have to separate my single class to let's say 3-5 separated class.
The problem is, how to make sure someone else(maybe new dev in my team), not accessing "the other class" that previously/originally a private method in my original class?
Why in the Single responsibility principle you use a service to handle the create logic and not the model?, shouldn't a method inside the model be enough?
I didn't quite understand the Liskov substitution principle. Like what exactly is the problem there? Any other examples?
Thx 👍
you are genius
is there any package/class that can convert pdf into proper html/css,? i mean the pdf is resumes, and properly written documents only, and we want to convert them into html/css's? 😁
From my experience:
Always typehint variables and typehint returns. The return should not be mixed.
If working with 3rd party services - always use interfaces. Even when working with services like image upload ('Spatie medialibrary' for example), one day you might swap to something else. Better to create an interface and a class that controls that upload (in that case a class that talks to spatie medialibrary).
I partly agree in theory, but in practice - how many times did you ACTUALLY, in real-life, had to swap media library (or similar example) to something else?
In my experience, even if you do swap with something else, you usually have a different interface, because that other tool has different set of features or works in a different way.
So, using interfaces BEFORE you have at least two implementations of that interface, in my opinion, is overengineering and premature optimization.
Hi Povilas. I need suggestion. I'm using spatie media library for storing images. but how to give collection url to api user. How mobile app developer get media urls. Thank you
Read the package documentation for it, I remember they do have Media Collections or something like that.
@@LaravelDaily yes for web I can use media but for mobile app I don't think there's anything. I think I have to get get media my self and send it into response.
Which pages would you recommend to search laravel jobs
larajobs.com
8:56 Wouldn't the better solution to adding that new parameter in only one of the classes be to inject that param via the class constructor? This would retain LSP, as well as O/C.
I'm a bit confused ... under the I principle you replaced ReportInterface with ReportDataInterface and ReportDownloadInterface .... but then later in the D example you have ReportInterface $report - how does this work with the Data and Download interfaces you created in the previous section?
Could I do ReportDataInterface AND ReportDownloadInterface $report ? Because the report must have the two methods getData() and download() to work in the controller. Hope that makes sense 👍
That's a bit of misleading example, I agree. In real life, if you separate two interfaces, then likely you won't use those interfaces as dependency in methods at all.
@@LaravelDaily Thanks, I do find sometimes with Solid I dig my self into a corner with it. More of an art than a set of rules maybe.
this principle asked me when i apply position - Junior Laravel developer )
And how did it go for you? :)
@@LaravelDaily I knew only 1 principle and how to answer it and use it - single responsabilites ) Other responsabilities I missed(passed)
And I didn't get a job ;)
I don't think that missing principle was the main reason that you didn't get the job :) At least, that's not how I would hire/choose a junior :)
@@LaravelDaily ))) Thanks for supporting and for your videos. It's really helping a lot of people!
@@LaravelDaily Sadly, it could be. Maybe company works with large scale projects where this pricinple is applied. Junior developers could be easily confused with advanced code structure.
Excuse me, what would you recomend to use with laravel? Vue.js or react.js?
Vue is much more popular, with more examples.
@@LaravelDaily i see, thank you, ita just that im trying to update my knowledge in laravel, because last time i was using it with jquery, but in this days, thats way obsolete u.u, well now i know, thank you again :)
I liked developing with sublime, but phpstorm is far better! :)
Royal like from me. I use VScode.
When you code, constantly ask yourself two questions:
Question 1: Who and How will they use that code in the future?
Question 2: What may change in the future?
PHP ❤️💪🏼🔥🔥🔥
Na twojej stronie z kursem SOLID piszesz " Want to get a Senior Laravel developer position?
You probably need to master software design principles, like SOLID." .. Ale ja śledzę oferty pracy dla juniorów w których już trzeba znać i stosować zasady SOLID :( Źle myślę?
W ofertach dla juniorów podaje się że wymagana znajomość SOLID, ale ostatecznie często nie trzeba ich za dobrze znać. Pamiętaj, że wymagania w ofertach nie muszą być spełnione na 100% żeby zostać zatrudnionym, szczególnie jeśli czymś innym się zaimponuje.
@@doktoracula7017 Na razie nie udało mi się zaimponować rekruterom :( Ale cały czas się edukuje- czeka mnie refaktoring moich projektów na github- może wtedy to pomoże... i kolejna sprawa- chyba najgorsza dla mnie... język angielski - ale uczę się języka - może życia starczy :) hi hi
Pozdrówka
😊
In example when you use injected InvoceService in action you violation D principle:) because you used concrete class, not interface
Based on my practice - we need to create interfaces in situations when we are planning to create several implementations. Most of my interfaces have only one implementation, so i decided not to create interfaces, and bind components in IOC container using inplementation name instead of interface name.
8:00
PhpStorm: Excuse me?
Hate myself to ask, sorry to be that guy. But any coupon for early buyers ?
Not for early buyers this time.
But generally, you can get some discount on all my products, here: coupons.laraveldaily.com
honestly, for people like who live in worst country in the world(iran) course's price is to high...
it's basically salary of 1 months of work... :(
I would like to take this course but it's to high to pay for 1-2~ hrs course.
I can't give it away for free, but I can give some discount based on where you live:
coupons.laraveldaily.com
And this course could easily be longer, 5-6 hours, but I intentionally stripped it down to what you ACTUALLY need to know, without unnecessary stuff.
Sadly, SOLID principles you should know applying for first job, unless you are pre-junior/intern. No matter what stack, it is mandatory to know.