Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Facades: Convenient Static Interface

Understand how Laravel facades work and when to use them.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Common Facades
  2. Real-Time Facade
  3. Create Custom Facade
  4. Testing with Facades

Understanding facades:

Common Facades

php
Cache::get('key');
DB::table('users')->get();
Route::get('/', fn() => view('home'));
Log::info('Message');

Real-Time Facade

php
use Facades\App\Services\PaymentService;

PaymentService::process($order);

Create Custom Facade

class Cart extends Facade
{
    protected static function getFacadeAccessor()
    {
        return 'cart';
    }
}

Testing with Facades

php
Cache::shouldReceive('get')
    ->once()
    ->with('key')
    ->andReturn('value');
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read