The problem with the facade and service provider in Laravel-4

I am trying to customize the facade for a custom class in laravel-4. However, when I try to load my site, I get an error message that reads

Class 'PlaneSaleing\ResizerServiceProvider' not found

I followed the tutorial here: http://fideloper.com/create-facade-laravel-4

My custom class is called Resizer.php and is stored in laravel\app\library\ and looks like this:

 <?php namespace PlaneSaleing; class Resizer { // My custom methods } 

Then I created a facade called ResizerFacade.php , saved in the same folder, and it looks like this:

 <?php namespace PlaneSaleing\Facades; use Illuminate\Support\Facades\Facade; class Resizer extends Facade { protected static function getFacadeAccessor() { return 'resizer'; } } 

Thirdly, I created the ResizerServiceProvider.php file and saved it in the same folder, which looks like this:

 <?php namespace PlaneSaleing; use Illuminate\Support\ServiceProvider; class ResizerServiceProvider extends ServiceProvider { public function register() { // Register 'resizer' instance container to our UnderlyingClass object $this->app['resizer'] = $this->app->share(function($app) { return new Resizer; }); // Shortcut so developers don't need to add an Alias in app/config/app.php $this->app->booting(function() { $loader = AliasLoader::getInstance(); $loader->alias('Resizer', 'PlaneSaleing\Facades\Resizer'); }); } } 

Finally, I added the following line to the file 'providers' => array (...) in laravel/config/app.php

 'PlaneSaleing\ResizerServiceProvider', 

Any help greatly appreciated

+4
source share
1 answer

You need to add the application / library to the composer's autoload path, and then restore the autoloader using a makeshift machine.

The second error you get (the "PlaneSaleing \ AliasLoader" class was not found) is that the ResizerServiceProvider class is in the PlaneSaleing namespace and this class is trying to call AliasLoader, which is not in the same namespace.

You just need to add \ in front of AliasLoader to indicate that it is in the main namespace instead of the current namespace.

+4
source

Source: https://habr.com/ru/post/1498473/


All Articles