Reputation: 3207
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:
Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class
However, the path to this class is tymon\jwt-auth\src\JWTAuthServiceProvider.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?
Upvotes: 1
Views: 1131
Reputation: 73301
This
Tymon\JWTAuth\Providers\JWTAuthServiceProvider
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 FullNamespace\Name\To\Class
at the top of your file, e.g. have a look at one of your controllers, it's the same as here:
<?php namespace App\CreateTables;
use Config;
use Illuminate\Database\Schema\Blueprint;
use MeineBuyBox\UserDatabase;
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.
Upvotes: 1