Adding Composer Package to Laravel Providers array

I'd like to understand how the path for various composer packages is constructed in the providers array of the app.php in Laravel. Some documentation include the line you need to copy/paste but I want to find out how to do this myself.

Example

The JWTAuth package has the following line:

TymonJWTAuthProvidersJWTAuthServiceProvider::class

However, the path to this class is tymonjwt-authsrcJWTAuthServiceProvider.php

I want to know how this path is constructed.

Next I want to know how I can include the Woothemes/Woocommerce api package in the providers array. How do I construct this path?

The package can be found at https://packagist.org/packages/woothemes/woocommerce-api

I have done some research and found that this package is not specifically written for Laravel. The bootstrap file woocommerce-api.php just contains the require_once() functions for the classes.

Would it be acceptable to do,

require_once base_path('vendor/woothemes/woocommerce-api/woocommerce-api.php');

in my controller file?


This

TymonJWTAuthProvidersJWTAuthServiceProvider

is not a filesystem path, it's the class' namespace.

As the package you linked to isn't written for laravel, there is no ServiceProvider for it yet, but you are free to create one.

However, you can use every external package without a ServiceProvider in laravel. You wouldn't require_once anything, but you would

use FullNamespaceNameToClass

at the top of your file, eg have a look at one of your controllers, it's the same as here:

<?php namespace AppCreateTables;

use Config;
use IlluminateDatabaseSchemaBlueprint;
use MeineBuyBoxUserDatabase;
use Schema;

That way, the class you intend to use will be loaded in the file you need it to be in and you can use it now.

链接地址: http://www.djcxy.com/p/88646.html

上一篇: 无法加载Non

下一篇: 将Composer包添加到Laravel Providers阵列