Laravel Make Facades

Laravel Make Facades Package


Overview


Description

Clean Code Studio package to generate  Facades in a single command -  php artisan make:facade MyCoolService

Installation


composer require clean-code-studio/laravel-make-facades --dev


Publish


php artisan vendor:publish

Select: CleanCodeStudio\MakeFacades\ServiceProvider



Define Service Config Settings

config/make-facades.php


Default Service Config Settings

config/make-facades.php 

return [

   // Directory path save your facades

   'path' => 'app/facades',


  // Namespace Of Your Facades

  'namespace' => 'App\\Facades',


  // Providers path (@see https://github.com/zhorton34/laravel-make-facades/issues/4)

  'providers_path' => 'app/Providers',

  

  // This will find all of the aliases and services defined in your path settings and

  // 1. Bind the service classes for each facade to the service container automatically

  // 2. Register aliases for each facade base on the Class Name the Facade Reference to the service container automatically

  'auto_alias_facades' => true,

];


Make Facades

php artisan make:facade MyCoolService


Default ServiceClass Scaffold

Default creation format: App\Facades\MyCoolService\MyCoolService.php

<?php


namespace App\Facades\MyCoolService;


class MyCoolService

{

    // create MyCoolService class

}


Default ServiceClassFacade Scaffold

By Default created at App\Facades\MyCoolService\MyCoolServiceFacade.php

<?php


namespace App\Facades\MyCoolService;


use Illuminate\Support\Facades\Facade;


class MyCoolServiceFacade extends Facade

{

    protected static function getFacadeAccessor()

    {

        return 'MyCoolService';

    }

}


Important Note

If 'auto_alias_facades' => false in config/make-facade.php then you need to

Bind generated service class (Example MyCoolServiceClass) to the service container whenever you create a new facade and service scaffold via running the make:facade command.

If auto_alias_facades is set to true then it will register the service class (Example MyCoolServiceClass) to the service container automatically.


Closing 


 Notes


Open Service Config File


config/make-facades.php