It's the first time that I try to load a Composer package that doesn't use a Laravel service provider or a facade.
I am trying to install this package: https://github.com/mollie/mollie-api-php
I have followed the steps to install the package with Composer.
At the top of my controller I added:
require_once base_path('vendor/Mollie/API/Client.php');
I get the following error:
main(): Failed opening required '../vendor/Mollie/API/Client.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.0/lib/php')
It can't find the file. Even though the path in the error is the path where the class is located. Are there more steps I should do?
Structure of the package:
composer.json
from the package:
"autoload": {
"psr-0": {
"": "src/"
}
Update: My controller has this namespace
namespace App\Http\Controllers;
So when i just try to new up my class it obviously can't find that class inside that namespace. So how do i ignore the namespace for 1 class
Because this will not work inside this controller:
$mollie = new Mollie_API_Client;
Via Download. Once Composer is installed, download the 4.2 version of the Laravel framework and extract its contents into a directory on your server. Next, in the root of your Laravel application, run the php composer. phar install (or composer install ) command to install all of the framework's dependencies.
Publishing Composer packages from a Space Git repository Make sure your PHP library is prepared for distribution – your PHP project has a valid composer. json file. The project is stored in a Space Git repository. In Space, open the repository page and click Submit Composer Packages.
phar file and running commands on it. You do not need to run Composer on your server as well as locally, once you run composer install or composer update your project will have all its dependencies available and you can just upload it straight to your server. Hope it helps!!
Composer in Laravel is used to manage their dependencies. Once Composer is installed, download the framework and extract its contents into a directory on your server. The primary task you should do after installing Laravel is to set your application key to a random string.
As noted in the comments, Composer handles the autoloading for you - manually re-requiring it isn't necessary and may in fact cause problems.
my controller has a namespace, so it tries to load that class from the namespace, how do i ignore it for 1 class?
You can reference the class with a leading \, i.e. new \Mollie_API_Client
, which will tell PHP to look in the root instead of your controller's namespace.
You can also put use Mollie_API_Client;
at the top of the file to accomplish a similar thing. You'll see use
statements at the top of a lot of Laravel files for this reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With