Home  >  Article  >  Backend Development  >  What is the significance of facades in Laravel?

What is the significance of facades in Laravel?

WBOY
WBOYOriginal
2016-12-01 00:25:201245browse

There are helper functions in Laravel, so why do you need Facades?
Does it have any advantages over using helper functions and directly accessing the underlying class?
(I can’t understand the document, so I asked this question)

Reply content:

There are helper functions in Laravel, so why do you need Facades?
Does it have any advantages over using helper functions and directly accessing the underlying class?
(I can’t understand the document, that’s why I asked this question)

It facilitates rapid development. There is no need to perform dependency injection operations on the container, and functions can be quickly implemented in the form of global variables, sacrificing maintainability in exchange for development speed.

If it is a global helper function, it is basically no different from Laravel's facade. One advantage of the helper function is that when we need to modify the function of the helper function or facade, we have to modify the code in the helper function. When using the facade, we Without modifying the facade code (when the program is initialized or already running), we can kill the singleton it actually points to and redirect it to a new singleton that meets our required functions to implement an ugly dependency injection, but it seems The facade does not provide an injection method by default, so you still need to modify the internal implementation of the facade.

By the way, do you have any recent laravel teaching videos

This question can be transformed into, why should we define a class if we can define a function.

Although it is a little troublesome to create, it is very convenient for subsequent development. Calling it directly with an alias can reduce a lot of code~~

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn