Skip to content
Advertisement

Create custom package with facade in Laravel 8

I am trying to develop a new Laravel package locally installed via Composer.

These are my steps:

  • I install a new Laravel application with composer create-project laravel/laravel my-application

  • I create a new directory in the root with the following content:

    packages/randolf/custom-package/composer.json

    JavaScript

    packages/randolf/custom-package/src/CustomPackage.php

    JavaScript

    packages/randolf/custom-package/src/CustomPackageServiceProvider.php

    JavaScript

    packages/randolf/custom-package/src/Facades/CustomPackageFacade.php

    JavaScript
  • I add my package in Laravel with composer, adding the repositories key: /composer.json

    JavaScript
  • I run composer update and the install, package discover and dump-autoload works correctly:

    JavaScript
  • I create a route in routes/web.php to test the facade:

    JavaScript

Result: laravel facade error

Advertisement

Answer

Adjust the alias in the composer.json to point to the Facade instead of its namespace:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement