简体   繁体   English

Laravel 8 - 未找到外观类

[英]Laravel 8 - Facade Class Not Found

I have been struggling with this after trying to replicate simple tutorials to get started a new project.在尝试复制简单的教程以开始一个新项目后,我一直在努力解决这个问题。

Folllowing the tutorials here: https://medium.com/@cmanish049/creating-custom-facades-in-laravel-b9b72d573752遵循此处的教程: https ://medium.com/@cmanish049/creating-custom-facades-in-laravel-b9b72d573752

  1. Created The Helper Function创建辅助函数

     namespace App\\CSVUtils; class CSVParser { public function sayHello() { echo "Hello, from Facade class."; } }
  2. Created The Service Provider创建服务提供者

    <?php namespace App\\Providers; use Illuminate\\Support\\ServiceProvider; use App\\CSVUtils\\CSVParser; class CsvParserServiceProvider extends ServiceProvider { /** * Register services. * * @return void */ public function register() { $this->app->bind('csvparser',function(){ return new CSVParser(); }); } /** * Bootstrap services. * * @return void */ public function boot() { $this->app->bind('csvparser',function(){ return new CSVParser(); }); } }
  3. Created the Facade创建了外观

    <? namespace App\\CSVUtils; use Illuminate\\Support\\Facades\\Facade; class CSVParserFacade extends Facade { protected static function getFacadeAccessor() { return 'csvparser'; } }
  4. Added the following to the app/config.php (I did not remove any of the default entries just added the following将以下内容添加到 app/config.php (我没有删除任何默认条目只是添加了以下内容

    'providers' => [ App\\Providers\\CsvParserServiceProvider::class, ... ], 'aliases' => [ 'CSV' => App\\CSVUtiles\\CSVParserFacade::class, ... ]
  5. Called the Alias in the my controller在我的控制器中调用别名

    <?php use Illuminate\\Support\\Facades\\Route; Route::get('/csv', function () { CSV::sayHello(); //return view('welcome'); });

RESULT:结果:

ErrorException Class "App\\CSVUtiles\\CSVParserFacade" not found http://localhost/csv ErrorException 类“App\\CSVUtiles\\CSVParserFacade”未找到 http://localhost/csv

Illuminate\\Foundation\\Bootstrap\\HandleExceptions::handleError vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php:80 Illuminate\\Foundation\\Bootstrap\\HandleExceptions::handleError vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php:80

I have tried a bunch of things, renaming classes / files changing the namespace, calling the Facade directly (rather than from the alias)我尝试了很多东西,重命名类/文件更改命名空间,直接调用 Facade(而不是从别名)

I have also tried the following:我还尝试了以下方法:

composer dump-autoload php artisan config:clear php artisan cache:clear php artisan clear-compiled composer dump-autoload php artisan config:clear php artisan cache:clear php artisan clear-compiled

And now I feel like I'm loosing my mind.现在我觉得我正在失去理智。 It's been a busy day and my brain is fried but I'm hoping I am missing something simple.这是忙碌的一天,我的大脑被炸了,但我希望我错过了一些简单的东西。

Please help!!请帮忙!! :) :)

Update below code - aliases for CSV :更新以下代码 - CSV 的别名:

'providers' => [
     App\Providers\CsvParserServiceProvider::class,
     ...
   ],

 'aliases' => [

     'CSV' => App\CSVUtils\CSVParserFacade::class,

     ...
 ]

Just a little spelling mistake.只是一个小的拼写错误。 Correct the spelling in app.php aliases array.更正 app.php 别名数组中的拼写。

Use this line of code使用这行代码

'CSV' => App\\CSVUtils\\CSVParserFacade::class, 'CSV' => App\\CSVUtils\\CSVParserFacade::class,

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM