Trying to use custom facades results in a "Call to an undefined method" in the :: create () application in Laravel?

I'm trying to create my own facade for the search function, but I'm having a little difficulty:

type: Symfony\Component\Debug\Exception\FatalErrorException message: Call to undefined method Illuminate\Foundation\Application::create() file: H:\myproj\vendor\laravel\framework\src\Illuminate\Container\Container.php line: 165 

This error is caused by a code hit:

 Search::indexObject(); 

Where is my Search facade configured as follows:

SearchServiceProvider

 <?php namespace MyProj\Search; use Illuminate\Support\ServiceProvider; class SearchServiceProvider extends ServiceProvider { public function register() { $this->app->bind('search', 'MyProj\Search\Search'); } } 

Search Facade

 <?php namespace MyProj\Facades; use Illuminate\Support\Facades\Facade; class Search extends Facade { public static function getFacadeAccessor() { return 'search'; } } 

Search class

 <?php namespace MyProj\Search; use Elasticsearch\Client; use Credential; class Search { private $elasticSearchClient; public function __construct() { $this->elasticSearchClient = new Client(array( 'hosts' => [Credential::ElasticSearchHost] )); } public function indexObject($object) { // Code return $this->elasticSearchClient->index($params); } public function get() { return $this->$elasticSearchClient; } } 

I successfully executed composer dump-autoload and my facade and services provider loads in app.php as follows:

an array of aliases

 'Search' => 'MyProj\Facades\Search', 

Array of suppliers

 'MyProj\Search\SearchServiceProvider' 

I spent the last 30 minutes debugging and searching for this error without any fixes. What's going on here?

EDIT: I added to the stack trace, which you can see below. Also, I see that getFacadeAccessor() is being called correctly, but anything that is beyond my understanding,

enter image description here

The highlighted frame represents the last case of normal operation, both frames on Handler.php represent formatting and error output at the top of the question.

+5
source share
1 answer

Estimate that this is a slightly old stream, however, you may get the described problems if the compiled cache was not cleared after adding a new facade.

You should run:

php artisan clear-compiled

+2
source

All Articles