Skip to content
Goravel/ Docs
Docs/Architecture Concepts/FacadesCore layer

Facades ​

Introduction ​

facades provide a "static" interface for the core functionality of the application and provide a more flexible, more elegant, and easy-to-test syntax. All facades of Goravel are defined under the app/facades folder:

go
import "app/facades"

facades.Config().GetString("app.host")

How Facades Work ​

Each service provider registers its corresponding bindings in the service container, then the service container provides various Make* functions to build the binding instances. The facades in the app/facades folder call these Make* functions to get the instances from the service container. Let's use the Route facade as an example:

  1. The Route service provider registers the binding.Route binding in the service container:
go
type ServiceProvider struct {}

func (r *ServiceProvider) Register(app foundation.Application) {
	app.Singleton(binding.Route, func(app foundation.Application) (any, error) {
		return NewRoute(app.MakeConfig())
	})
}

func (r *ServiceProvider) Boot(app foundation.Application) {}
  1. The Route facade calls the MakeRoute() function to get the Route instance from the service container:
app/facades/route.go
package facades

import (
	"github.com/goravel/framework/contracts/route"
)

func Route() route.Route {
	return App().MakeRoute()
}

TIP

Because facades are exposed to the application, you can create your own facades or override the existing ones in the app/facades folder.

Install/Uninstall Facades ​

goravel/goravel installs all facades by default and goravel/goravel-lite only installs essential facades like Artisan, Config. You can install or uninstall other facades as needed via the package:install and package:uninstall commands.

shell
# Install a specific facade
./artisan package:install Route

# Install all facades
./artisan package:install --all

# Install all facades with default drivers
./artisan package:install --all --default

# Uninstall a specific facade
./artisan package:uninstall Route

TIP

If you are using the ./artisan package:install command to choose the facades manually, you need to press x to select the facades you want to install, then press Enter to confirm. facades are not selected if you directly press Enter.

Released under the MIT License