What in the world is a Facade?

  Рет қаралды 8,876

Laravel

Laravel

Күн бұрын

Laravel facades serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods. It's perfectly fine if you don't totally understand how facades work - just go with the flow and continue learning about Laravel.
If reading is more your style, first check out the Facade documentation. The Facade classes have a __callStatic which first checks for the container binding ID by calling static::getFacadeAccessor() (see laravel.com/do...) and then uses that to get the real underlying class from the DI Container.
Once that's complete, then calls the actual method wanted (i.e. __callStatic arg) (see github.com/lar....
Facade Documentation:
laravel.com/do...

Пікірлер: 62
@guillermocava3568
@guillermocava3568 2 ай бұрын
Gotta be honest, for the longest of time I've read Facades/Facade in my head as "fa-ka-de"
@vieiraork
@vieiraork 2 ай бұрын
Me too man
@ernestojaboneta
@ernestojaboneta 2 ай бұрын
Me tooo!!
@LaravelPHP
@LaravelPHP 2 ай бұрын
Same. 😬 -Josh
@TalesGrechi
@TalesGrechi 2 ай бұрын
No matter where you look on the laravel documentation you're bound to run into the word facade, indeed! 😂
@freizusavera9096
@freizusavera9096 2 ай бұрын
Did anyone understand anything from this video? As facades were a mystery, so it remains for me. Why not create your own facade from scratch, to show in practice what problem it solve. kzbin.info/www/bejne/naHRkGeqjN9krZo 0:35 “allowing you to have that flexibility of testing or dependency injection” Why/how, where are the answers to these questions? They say “it's cool and that's it”, but where are the real examples, show how solving some practical problem looks like without facades and how development/testing/other things are easier with facades. It appears that the video is published just so something would be on the channel and views, and not to educate people and popularize framework, and showing what problems developers face and how laravel effectively solves them. The person in the comments wrote: "Facade pattern is not what static Facades in laravel are. This make your code 100% coupled with laravel. You don't want that! Use IoC instead... I don't like that in laravel - just ugly and wrong design!" You could have elaborated more on this as well, not only the advantages but also the disadvantages of using facades.
@victortodoran1828
@victortodoran1828 Ай бұрын
It's a 'static proxy' to the actual service, it's just syntactic sugar that allows you to use a service without injecting it or grabbing from the container. They(Laravel) leverage the php magic method __callStatic to make the code using these 'Facades' testable, in other words to give the possibility to mock these static calls. I'm not going to go too much into the benefits, it's mostly speed and convenience and they might offer some flexibility in case you are developing a public package, in the sense that you do not break backwards compatibility when adding another dependency in the constructor of your publicly available class. Keep in mind that I'm neither an expert or advocate of Laravel or this particular concept. Personally I don't like it because it obfuscates the dependencies that a class has. Laravel is not forcing you to use facades you should be able to inject any service (available through a 'Facade') in the constructor or grab it from the container. Check the docs for more laravel.com/docs/11.x/facades Here is a thoughtful excerpt from the docs: _However, some care must be taken when using facades. The primary danger of facades is class "scope creep". Since facades are so easy to use and do not require injection, it can be easy to let your classes continue to grow and use many facades in a single class. Using dependency injection, this potential is mitigated by the visual feedback a large constructor gives you that your class is growing too large_ I hope this comment helps. Cheers
@taylorackley8202
@taylorackley8202 2 ай бұрын
Very well done, Josh! Facades as a concept are a tough topic to explain well and you knocked it out of the park!
@LaravelPHP
@LaravelPHP 2 ай бұрын
Thanks so much Taylor! I appreciate the support. :) -Josh
2 ай бұрын
What a voice. It feels you're speaking directly to my soul
@LaravelPHP
@LaravelPHP 2 ай бұрын
Thank you. 🥹 -Josh
@sllkevin8885
@sllkevin8885 2 ай бұрын
First rule of learning about Facades, don’t worry about learning Facades.
@LaravelPHP
@LaravelPHP 2 ай бұрын
This is the way. 👀 -Josh
@devi-id9xp
@devi-id9xp 2 ай бұрын
Hi Josh, just a feedback on your Mic volume. Do you really prioritize the ASMR sound rather than the volume level of it? I mean its really good if one is wearing a headset but for those who not, the volume level is kinda low. Thanks!
@LaravelPHP
@LaravelPHP 2 ай бұрын
Hey there. We do try to have all volume level at around -6db so I’m sorry to hear that you are not able to hear it properly. We will look into boosting overall levels. -Josh
@chris-uit-balen
@chris-uit-balen 2 ай бұрын
High quality video, well spoken! Yet, I still don't get it. I would have hoped to see a coding example of a piece of code written without extending facade comparing it with a simpler version that does make use of the benefits of facades. Thanks! Chris
@LaravelPHP
@LaravelPHP 2 ай бұрын
Thanks Chris! This was meant to be a Quick Look and to really have a video version of the docs but it seems like this would be an incredibly helpful video to expand upon so be looking for a part two coming soon. :) -Josh
@narrei666
@narrei666 2 ай бұрын
what do you mean no need for static keyword? for example if i want to have User::getDefaults() method, i add public static function getDefaults() to my user model. is this a bad practice?
@LaravelPHP
@LaravelPHP 2 ай бұрын
The static keyword is still a great option, especially if it's closely tied to a model and doesn't require external dependencies. Usually, most people reach for Facades (or why standard Laravel features are setup as Facades) when you need to have easier mock calls for testing or leverage the service container for dependency injection. So, nope. Not bad practice at all! :) Facades just provide a static-like interface for non-static classes. And in your example, it's clear it's related to the User, it doesn't require an instance of User to operate, so no need for a Facade. :) -Josh
@elgoogssie3969
@elgoogssie3969 2 ай бұрын
I was worried to :)
@MaulikParmar210
@MaulikParmar210 2 ай бұрын
​@LaravelPHP ah wait most services are singleton by nature even though they are regular classes and DI container only keeps one instance of the service unless you tell it explicitly. So no, there are no good or bad practices, it's m just same as calling service from DI. under the hood class can be normal, static or singleton to serve the purpose and registered scoped or shared depending on requirements. Funny how DI hides it and how Facade is injected with application instance makes it all the difference.
@mikechurvis2762
@mikechurvis2762 2 ай бұрын
Static methods cannot be mocked during tests. If you're testing your work as much as you should, you may find most static things to be more trouble than they're worth. You're probably aware of the $attributes array property for default model values; if you're doing more processing than that to compute/retrieve your defaults, I've found 4/5 times that inside the model is the wrong place to do that.
@MaulikParmar210
@MaulikParmar210 2 ай бұрын
@@mikechurvis2762 that's a framework design and implementation problem, not a language problem, you can swap underlying classes without changing outside API, it would still work, thay how most DI container does it anyways. Static can still have variable instances in memory, static only means memory sticky to runtime, only single allocation happens. Allocation still happens on the fly. Depends on how you view it, methods can use variables that references objects and as long as objects are referenced, they can be swapped in preparation phase via classes getter setters, no need to stick them literally.
@julienSibille
@julienSibille 2 ай бұрын
Would love to see a use case
@elgoogssie3969
@elgoogssie3969 2 ай бұрын
Need to read about it. As i do understand helper function/custom helper functions. I do not get the facades.
@iosfactory
@iosfactory 2 ай бұрын
really great video
@LaravelPHP
@LaravelPHP 2 ай бұрын
Thanks for watching! -Josh
@coolcha
@coolcha 2 ай бұрын
I still don't get it but I am fine going on without knowing it 😅
@dominikbetlej7114
@dominikbetlej7114 2 ай бұрын
Thx
@LaravelPHP
@LaravelPHP 2 ай бұрын
Thanks for watching. :) -Josh
@algeriennesaffaires7017
@algeriennesaffaires7017 2 ай бұрын
Laravel team becareful you guys are making Laravel a complex framework it was a hell of coomlex route i almost gave up on Laravel when i started learning it and i assure you future developers wont care about your fancy tech or names they like simplicity and if Laravel keep getting complex ill ditch it and go back to CodeIgniter
@fasterisq2.1m76
@fasterisq2.1m76 2 ай бұрын
Yeah absolutely. Laravem make things complex😂 - to send a mail: make a event using php artisan:make event UserRigistered and make a mail class using php artisan make:mail and create constructor, create a blade template and make a listener using php artisan make:listener SendWelcomeNotification and call the mail class in inside and finally register the listener in eventServiceProvider with the events😂 it's simplee😂😂 - to make a table with foreign key, first: pho artisan make:migration users and write table structure in up method with a unsignetinteger type 'company_id' column and then write another line to link this column to companies table😂 then write code to delete the table in down method and then make a User model using command pho artisan make:model User😂 than define a relationship method inside model to link in companies table (note: we already defined in migration too😂)...
@fasterisq2.1m76
@fasterisq2.1m76 2 ай бұрын
They daily come with some fancy helper functions like function to convert string to upper case, function to convert string to number 😂 it's very very very usefull😂😂
@fasterisq2.1m76
@fasterisq2.1m76 2 ай бұрын
And they laravel comes with factory and seeder it's very very useful when our application goes to overload😂 To insert some data to users table: make a seeder class using php artisan make:seeder UserSeeder and make a factory using php artisan make: factory UserFactory and call the factory in seeder class and finally call the seeder class in database seeder.php , this is the very simplest (not complex) and fancy way to scale our backend application instead of inserting directly some records to a table So this isthe best and good way forseperation of concern principle (we made a facories folder with userfactory and a seeder folder with userseeder ) and very structured (not complicated and bloatwared)😂😂😂
@med.brunofreire
@med.brunofreire 2 ай бұрын
And it extends to the new trend of “Full Stack Laravel”. I don’t understand this fetish with Livewire and Blade (they want to force you to use this techs in the frontend). So, now, when you create a new project for a simple api, you have an additional step “php artisan install:api”. That’s unreasonable given the majority of frontends are written in JS, SPAs. Livewire is slow by this architecture of making requests to the server every single click, type or command on the front end.
@fasterisq2.1m76
@fasterisq2.1m76 2 ай бұрын
Livewire is not to use in our product, it used to get fresher developers attention by making fancy things
@joao-pedro-alves
@joao-pedro-alves 2 ай бұрын
Excelent content although I'm still very convict that Facades are a bad thing haha
@LaravelPHP
@LaravelPHP 2 ай бұрын
That’s okay! :) -Josh
@lerizmor5858
@lerizmor5858 2 ай бұрын
Hi Josh, what's with this guru voice?
@LaravelPHP
@LaravelPHP 2 ай бұрын
I don’t mean to use any sort of voice. 😂 I’m learning with all of you too. :) -Josh
@khanra17
@khanra17 Ай бұрын
Toooooo annoying
@MauiWowie51
@MauiWowie51 2 ай бұрын
save yourself this video and just google the word. it means the front of a building.
@DiDiR6
@DiDiR6 2 ай бұрын
Facade = Front side of a building in French 😅
@winter-survivor
@winter-survivor 2 ай бұрын
It's also called "buzz word".
@lenkowski-net
@lenkowski-net 2 ай бұрын
Facade pattern is not what static Facades in laravel are. This make your code 100% coupled with laravel. You don’t want that! Use IoC instead… I don’t like that in laravel - just ugly and wrong design!
@davidlrogers
@davidlrogers 2 ай бұрын
ol' boy really thinks he has the high ground, forgetting that he's writing OOP/PHP 🤣
@lenkowski-net
@lenkowski-net 2 ай бұрын
@@davidlrogersthis way of thinking (PHP is bad) is just a sign that you don’t know it well… You can write clean code in PHP definitely better than in TypeScript for instance. I saw so much great code in PHP and in the same time so much bad code in Java or C# as an example… Stop saying there is an issue with PHP. The issue is with some construction on Laravel (like facade or helpers). But language year by year is slightly better.
@necmettinb
@necmettinb 2 ай бұрын
So a face is basically a lie 😊. It’s literally int the name. 😂
@fasterisq2.1m76
@fasterisq2.1m76 2 ай бұрын
Its time to stop the implement ing new fancy features daily and remove unnecessary fancy things make it simple and minimal. Its noot good to applyseperation of concern and other priple blindly to our laravel make more complicated and unnecessary files and folders. No one gonna vuild and deploy a product with your fancy things like livewire to production and stop this instead of making nonsense developers and media attention. Just try a small project in nodejs and you can feel the difference
@med.brunofreire
@med.brunofreire 2 ай бұрын
@@fasterisq2.1m76 That’s true. I hate Livewire, is the worst thing in Laravel. No medium size projects uses “Full Satck Laravel”. It is gross, slow. These guys are tripping.
@med.brunofreire
@med.brunofreire 2 ай бұрын
@@fasterisq2.1m76 if you want to create a simple Laravel Rest API, you have to run an additional command “php artisan install:api”. This is crazy! Who was the dev that accept the PR with this gross? The documentation follows the same pattern, you do not find easily the command to enable RestApi in Laravel11. They want to force you into the Blade/“Lazywire” thing…
@md.redwanhossain6288
@md.redwanhossain6288 2 ай бұрын
You are mixing and marching object oriented approach and functional approach. NodeJS is a disaster regarding architecture unless you use NEST JS which is also complex.
@davidlrogers
@davidlrogers 2 ай бұрын
Facades have been a feature for over a decade lol. and while i personally liked using NodeJS, (though the even creator has plenty of beef with it these days) it's not a framework. if you don't want to use a framework, then don't use a framework; whining about others using them seems pretty dumb ngl.
@khanra17
@khanra17 Ай бұрын
Eww brotha, ewww speak louder and keep distance from the mic eww
What’s Up with Laravel? It’s Everywhere, and Here’s Why!
6:22
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
«Кім тапқыр?» бағдарламасы
00:16
Balapan TV
Рет қаралды 244 М.
小路飞嫁祸姐姐搞破坏 #路飞#海贼王
00:45
路飞与唐舞桐
Рет қаралды 29 МЛН
She's very CREATIVE💡💦 #camping #survival #bushcraft #outdoors #lifehack
00:26
Which Livewire method should I use?
8:20
Laravel
Рет қаралды 7 М.
Authorization in Laravel: Can You Do That?
8:29
Laravel
Рет қаралды 9 М.
BEWARE these Laravel attributes | Real World Laravel
19:10
Sam Lewis
Рет қаралды 4,7 М.
Stop With Software Estimates
16:54
ThePrimeTime
Рет қаралды 143 М.
Every Framework Sucks Now
24:11
Theo - t3․gg
Рет қаралды 138 М.
Laravel First Impressions From A JavaScript Dev
21:08
adamdotdev
Рет қаралды 134 М.
It’s time to move on from Agile Software Development (It's not working)
11:07
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 286 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,5 МЛН
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17