Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel integration doesn't work #34

Open
BrunoTeixeiraNavila opened this issue Feb 22, 2017 · 11 comments
Open

Laravel integration doesn't work #34

BrunoTeixeiraNavila opened this issue Feb 22, 2017 · 11 comments

Comments

@BrunoTeixeiraNavila
Copy link

Class 'App\Http\Controllers\Front\Shippo_Shipment' not found

@mootrichard
Copy link
Contributor

mootrichard commented Feb 24, 2017

Is Shippo inside of your vendors folder of your Laravel installation?

Also, do you have require_once('vendor/autoload.php'); or require_once('/path/to/vendor/shippo/shippo-php/lib/Shippo.php'); in your file for loading Shippo?

Any additional details about your configuration would be really helpful in troubleshooting why the class isn't being found.

@casperbakker
Copy link

Looks to me like your missing a backslash in front of Shippo_Shipment. This package is not namespaced, so you need to use \Shippo_Shipment::create() or add a use statement in the head of the file.

@pardeep7387
Copy link

Hi Casperbakker
I am learning laravel and got shippo library to hands on with laravel. I couldn't understand how to integrate shippo in laravel. I am not sure how to bind.

To use the bindings, either user Composer's autoload:

require_once('vendor/autoload.php');
Or manually:

require_once('/path/to/vendor/shippo/shippo-php/lib/Shippo.php');

Please let me know Steps in easy and learners way so that i can understand. i am totally novice.

@pardeep7387
Copy link

I am getting error after adding this \Shippo::setApiKey($this->app['config']['services.shippo.key']); to service.php.

ERRROR:
C:\wamp64\www\shippo>php artisan serve

[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected 'config' (T_STRING), expecting ']'

My services.php looks like this after adding line

'mailgun' => [
    'domain' => env('MAILGUN_DOMAIN'),
    'secret' => env('MAILGUN_SECRET'),
],

'ses' => [
    'key' => env('SES_KEY'),
    'secret' => env('SES_SECRET'),
    'region' => 'us-east-1',
],

'sparkpost' => [
    'secret' => env('SPARKPOST_SECRET'),
],

'stripe' => [
    'model' => App\User::class,
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
],

** \Shippo::setApiKey($this->app['config']['services.shippo.key']);**

];

@casperbakker
Copy link

This has nothing to do with Laravel, it is just normal PHP namespacing.

This package is recommended to use with composer, if you do that in a blank PHP project, you need the require_once('vendor/autoload.php');. (Never use the manually method.)

But, with Laravel that autoloader is already loaded by the framework. So you can just use those classes as normal, without the need for including files.

If you are getting Class 'App\Http\Controllers\Front\Shippo_Shipment' not found, it is useful to read up on using namespacing in PHP. But as an easy start: you need to include the whole namespace with a leading backslash, so \Shippo_Shipment. Otherwise it will add the current namespace you are in, in front of the class you are using. So you where probably in a class inside the App\Http\Controllers\Front namespace, so using Sippo_Shipment without a backslash will search for that class inside that namespace. Just like relative/absolute URI's.

@casperbakker
Copy link

You can simple not add any PHP to any of the files in the config/ directory, other then things that are added to that array.

It is probably a bad idea to load Shippo on every request. But if you want that, you should add that in a ServiceProvider, or just in the code right before doing something with the Shippo client.

But this is just basic Laravel, it has nothing to do with this Shippo library. Maybe read a bit more of the Laravel docs? They are pretty good.

@pardeep7387
Copy link

Please let me know how to integrate "shippo-php-client" in laravel and how to test laravel project.

@casperbakker
Copy link

Haha, please do my work for me.

This is just basic PHP stuff. You have to figure some things out for yourself.

@pardeep7387
Copy link

Thanks Brother! #

@Nacoma
Copy link
Contributor

Nacoma commented May 11, 2017

A note on the service provider:

If he sets the defer flag on his service provider then the closure will only be evaluated when it is retrieved from the container. This will have a much smaller footprint while still letting him inject the service.

Although I think that is beyond the scope of his problem.

@packytagliaferro
Copy link

I have it working fine in my Laravel project. Follow this guide:

Laravel + Shippo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants