Laravel 5.1 - Error creating / using custom facade

0

Create a class, add the Service Provider and try calling a method, for example, "test ()" and it works. Next I create a facade in "app / Facades / MyClass.php":

<?php

namespace App\Facades;
use Illuminate\Support\Facades\Facade;

class MyClase extends Facade {

    protected static function getFacadeAccessor()
    {
        //return 'mc';
        //return 'MC';
        return 'mC';
    }

} //class

Other tests have been commented on to return the name of the facade to be used. ..

In "config / app.php", in the "aliases" array I have:

'MC' => App\Facades\MyClase::class,

Try calling it on "routes.php":

Route::get( 'mc-facade', function() {
    MC::test();
});

and in a controller ...

I have the following error message:

  

FatalThrowableError in Facade.php line 216: Fatal error: Call to   undefined method App \ Facades \ MyClass :: test ()

Testing in local with Xampp / Windows.

    
asked by Orici 30.10.2017 в 12:05
source

1 answer

0

I think you need to binde it in the provider

use Illuminate\Support\ServiceProvider;
class MyServiceProvider extends ServiceProvider{
    public function register()
    {
        $this->app->bind('mC', 'App\Facades\MyClase ' );
    }
}
    
answered by 30.10.2017 в 14:02