简体   繁体   中英

Laravel 5 FatalErrorException with a provider

I configured my config/app.php file and I added this provider:

'providers' => [
/*
  Foti Services Providers
*/
 Foticos\LaravelFotiServices\LaravelFotiServicesProvider::class,
],

I have created and added namespace to my LaravelFotiServicesProvider file:

<?php 

namespace Foticos\LaravelFotiServices;

use Illuminate\Support\ServiceProvider;

class LaravelFotiServicesProvider extends ServiceProvider {
...

But Laravel 5 reports me this error:

FatalErrorException in ProviderRepository.php line 146:
Class 'Foticos\LaravelFotiServices\LaravelFotiServicesProvider' not found

What´s the problem?

As you have placed your files inside the vendor folder, you should provide a directive in composer.json to let Laravel find your classes. But, be ware that placing your own files inside the vendor folder is not a good idea as it's usually used for third party libraries

You should place your source files inside the app folder, and they will be automatically PSR-4 namespaced under the namespace App because in composer.json is specified:

"psr-4": {
        "App\\": "app/"
    }

So, if you create a subfolder: app/Libs/Foticos/ the files inside the folder will have the App\\Libs\\Foticos namespace

Instead, if you want to create a package (to use the sources in more than one project, or to re-distribuite them) , check here to see how you should structure your folders for package-development

EDIT

If you absolutely want to leave your folder in vendor , try to add this to composer.json:

"psr-4": {
        "App\\": "app/",
        "Foticos\\": "vendor/foticos/laravel_foti_services/src/" 
    }

Then place the file in:

vendor/foticos/laravel_foti_services/src/LaravelFotiServices/LaravelFotiServicesProvider.php

And do: composer dump-autoload

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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