Integrating Laravel 5.2.* with firebase (Already tried j42) - php

I am facing the errors while using J42,
This is the composer.json I am using for the require element
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "^5.2"
I need to add firebase to my application, it is really important .
If anyone can provide me with the step by step installation along with an example it would be really great.
I have tried all sorts of possibilites
'Firebase' => J42\LaravelFirebase\LaravelFirebaseFacade::class
// `'Firebase' => J42\LaravelFirebase\LaravelFirebaseFacade
::class
even adding this class also seems an error since J42/laravel-firebase haven't mentioned it but nothing works without it.
I have already added J42/Laravel... to my composer.json but it also don't work, shows error App/Http/Controller/Firebase class not found
So if anyone could please help me in this issue, then it would be really great.
Thanks

Add the following line to your composer.json and run composer update:
{
"require": {
"j42/laravel-firebase": "dev-master"
}
}
Then add the service providers and facades to config/app.php
'J42\LaravelFirebase\LaravelFirebaseServiceProvider',
'Firebase' => 'J42\LaravelFirebase\LaravelFirebaseFacade'
Finally, you should configure your firebase connection in the config/database.php array.
Simple Access Token
'firebase' => array(
'host' => 'https://<you>.firebaseio.com/',
'token' => '<yoursecret>',
'timeout' => 10,
'sync' => false, // OPTIONAL: auto-sync all Eloquent models with Firebase?
)

Related

Class not found error with composer autoload

I must be making a simple error, I have not used Composer before now. I have followed the instructions on the GitHub page, but I'm getting a Class 'ZCRMRestClient' not found error when I load the page.
composer.json:
{
"require": {
"zohocrm/php-sdk": "^2.0"
}
}
PHP is
require 'vendor/autoload.php';
$configuration = array(
'client_id' => '1000.***',
'client_secret' => '***',
'redirect_uri' => '***',
'currentUserEmail' => '***',
);
ZCRMRestClient::initialize($configuration);
$contacts = ZCRMRestClient::getModule(“Contacts”);
echo "<pre>\n";
print_r($contacts);
echo "\n</pre>";
I've tried \ZCRMRestClient::initialize($configuration) but that hasn't helped.
There is new sdk 3.0 available, and the old sdk 2.0 is moved to:
"require": {
"zohocrm/php-sdk-archive": "^2.0"
}
I'm going to assume you've executed the composer require zohocrm/php-sdk command, or potentially added the requirement straight into your project's composer.json by hand.
Make sure you're importing the correct namespace for the library - in this case it seems to be zcrmsdk\crm\setup\restclient\ZCRMRestClient
You should write use zcrmsdk\crm\setup\restclient\ZCRMRestClient; at the top of the file then invoke methods as you currently do.
Alternatively, you can invoke methods as in the following example: \zcrmsdk\crm\setup\restclient\ZCRMRestClient::initialize($configuration);
After that the most likely problem is that your autoload file doesn't contain a reference to your library.
composer dump-autoload should fix that (from the command line.)
And finally perhaps you are not requiring the vendor folder correctly!

Laravel Class 'Intervention\Image\ImageServiceProvider' not found

this question is asked many times and I did all the introductions I could found but I still get this error message.
I updated my config/app.php (
providers:
Intervention\Image\ImageServiceProvider::class,
aliases:
'Image' => Intervention\Image\Facades\Image::class,
and the composer.json
"intervention/image": "dev-master",
After this I did a composer update but my error message is still the same.. I'm using laravel 5
I did what the link says:
http://image.intervention.io/getting_started/installation
and yeah.. now I'm stuck
Another thing I dont understand is why they say I should write:
'Intervention\Image\ImageServiceProvider'
in the provider array. Why the ' '? All the other elements in my provider array are written like this:
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
so I removed the ' ' and addet ::class
the same with the aliases
I dont know if thats okay but maybe someone of you could help me
thanks for help
The ::class operator gives the fully qualified class name and was introduced in PHP 5.5 as you can see here. It's perfectly ok to use it if you have PHP >= 5.5.
I would suggest to check in the vendor directory if the package exists. I use "intervention/image": "^2.3" and everything's working great on L5.1

Swift_Message not found error after swiftmailer installed in Yii2

I'm setting up a mailer in a project using Yii2. Swiftmailer seemed to be the best solution for this framework so I simply followed the docs.
In composer.json
"yiisoft/yii2-swiftmailer": "*"
Followed by:
composer install
In my config I have: (Yes, I just want it to save a file for now.)
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => true,
],
Then I placed this into a controller:
\Yii::$app->mailer->compose()
->setFrom('from#domain.com')
->setTo('to#domain.com')
->setSubject('Message subject')
->setTextBody('Plain text content')
->setHtmlBody('<b>HTML content</b>')
->send();
My error is:
PHP FATAL - Class 'Swift_Message' not found
I believe, after some research this has to do with the autoloader / lazy loading but the information I can find is spotty. Most of it states that if using composer to install resolves the issue, and all of my troubleshooting has left me chasing my tail.
Here's my stacktrace. Thank you for your help.
Additional:
composer-asset-plugin - IS INSTALLED
vendor/composer/autoload_files.php DOES contain the line:
$vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
I would love just close this embarrassment, but in case someone makes the same assumption as myself, i'd like to help.
Does you entry script contains 'vendor/autoload.php' require? Does it
point to the correct file? Try to manually put die('swiftmailer') at
'vendor/swiftmailer/swiftmailer/lib/swift_required.php' - it should
appear at any application run.
via (klimov-paul / yiisoft)
die('swiftmailer'); had no effect.
vendor/autoload.php is not required.
I had assumed that the other extensions already installed in the vendor folder were in use. I came to find that previous developers were not utilizing anything there and require(__DIR__ . "/../vendor/autoload.php"); was not in the execution path.

Laravel Omnipay with Omnipay/Paypal - Class not found

I'm trying to integrate the Omnipay Paypal package with my Laravel 4.1 application. I've installed the laravel-omnipay package, as suggested by Omnipay, and followed the instructions on how to set it up.
I've added the laravel-omnipay package to both the providers array and the aliases array in the app.php file of Laravel. The config file has also been created.
My composer.json has the following requirements:
"ignited/laravel-omnipay": "1.*",
"omnipay/paypal": "~2.0"
and the config file of ignited/laravel-omnipay looks like this:
<?php
return array(
// The default gateway to use
'default' => 'paypal',
// Add in each gateway here
'gateways' => array(
'paypal' => array(
'driver' => 'Paypal_Express',
'options' => array(
'solutionType' => '',
'landingPage' => '',
'headerImageUrl' => ''
)
)
)
);
But when I call $gateway = Omnipay::gateway('paypal'); I'm getting the error
Class '\Omnipay\Paypal\ExpressGateway' not found"
Is there something I'm forgetting? :I
I'm not familiar with ignited/laravel-omnipay specifically, so this may or may not be the problem, but you might try fixing the capitalisation on this line:
'driver' => 'PayPal_Express',
(note that PayPal has two capital P's).
Generally class names are not case sensitive in PHP, but if you are using a case-sensitive filesystem, then the composer autoloader will not be able to find the right class.
Try composer dumpautoload to load new classes.
UPDATE:
Think in a term of service that is provided to your application by that new package. Find where is that service linked to application. It is usually done through ServiceProviders class. If there is no bug, it should be easy, following simple business rule to see how is provider related to main app.
So, you have one entity (provider) that should communicate with another.
That communication is done through simple rules. This is the best way to learn Laravel. It helps to think in a term of business rules, rather then to stare at code which is often very abstract.

Using a non-laravel package on Laravel 4

Is it possible to include a package that was not specifically designed for L4 in the framework?
If so, how is it done? I know I need to add the package to my composer.json which adds it to the vendor folder, but can I register it somehow in the providers array? are there any other steps necessary?
I would like to use the Google checkout package originally designed for Yii
Using third party composer packages with Laravel 4
When developers create composer packages, they should map the auto-loading using PSR-0 or PSR-4 standards. If this is not the case there can be issues loading the package in your Laravel application. The PSR-0 standard is:
{
"autoload": {
"psr-0": { "Acme": "src/" }
}
}
And the PSR-4 standard:
{
"autoload": {
"psr-4": { "Acme\\": "src/" }
}
}
Basically the above is a standard for telling composer where to look for name-spaced files. If you are not using your own namespaces you dont have to configure anything else.
SCENARIO 1
PSR-0 standard following packages (with autoload classmap) in Laravel
This is a simple one, and for example i will use the facebook php sdk, that can be found:
https://packagist.org/packages/facebook/php-sdk
Step 1:
Include the package in your composer.json file.
"require": {
"laravel/framework": "4.0.*",
"facebook/php-sdk": "dev-master"
}
Step 2:
run: composer update
Step 3:
Because the facebook package uses a class map its working out of the box, you can start using the package instantly. (The code example below comes straight from a normal view. Please keep your logic out from views in your production app.)
$facebook = new Facebook(array(
'appId' => 'secret',
'secret' => 'secret'
));
var_dump($facebook); // It works!
SCENARIO 2
For this example i will use a wrapper from the instagram php api. Here there need to be made some tweaks to get the package loaded. Lets give it a try!
The package can be found here:
https://packagist.org/packages/fishmarket/instaphp
Step 1:
Add to composer .json
"require": {
"laravel/framework": "4.0.*",
"fishmarket/instaphp": "dev-master"
}
Then you can update normally (composer update)
Next try to use the package like you did with the facebook package. Again, this is just code in a view.
$instagramconfig = array(
'client_id' => 'secret',
'client_secret'=> 'secret',
'access_token' => 'secret'
);
$api = Instaphp::Instance(null, $instagramconfig);
var_dump($api); // Epic fail!
If you try the above example you will get this error:
FatalErrorException: Error: Class 'Instaphp' not found in ...
So we need to fix this issue. To do this we can examine the instagram composer.json, that has its autoload diffrent than the facebook php sdk had.
"autoload": {
"psr-0": { "Instaphp": "." }
}
Compared to the facebook composer.json:
"autoload": {
"classmap": ["src"]
}
(Composer handles different kinds of autoloading, from files and class-maps to PSR. Take a look at your vendor/composer/ folder to see how its done.)
Now we will have to load the class, manually. Its easy, just add this (top of your controller, model or view):
use Instaphp\Instaphp;
composer dump-autoload, and it works!
step2 (optional)
Another method is (if you dont want to use the "use" statement, you can simply tell composer to look for the files straight from your code. Just change the Instance like so:
// reference the name-spaced class straight in the code
$api = Instaphp\Instaphp::Instance(null, $instagramconfig);
var_dump($api); // It works
However I suggest using the usestatement to make it clear to other developers (and your future self) what (external) classes/packages are used in the program.
SCENARIO 3
Here we use the Laravels built in IOC container to register service providers. Please note that some packages might not be suitable for this method. I will use the same Instagram package as in scenario 2.
Quick and dirty
If you don't care about design patterns and service providers you can bind a class like this:
App::bind('Instaphp', function($app)
{
return new Instaphp\Instaphp;
});
And you resolve it like this.
App::make('Instaphp');
Quick and dirty end
If you're working on a bigger project, and you make use of interfaces you should probably abstract the bindings further.
Step 1:
Create a folder inside your app folder, for example a 'providers' folder.
app/providers
Make sure Laravel auto-loads that folder, you can pass in some additional info to composer.json, like this:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/providers" // this was added
]
},
Now create a File inside the new folder called Instagram.php and place this inside:
<?php
use Illuminate\Support\ServiceProvider;
class InstagramServiceProvider extends ServiceProvider {
public function register()
{
$this->app->bind('Instaphp', function()
{
return new Instaphp\Instaphp;
});
}
}
Now run composer dump-autoload again, and you can use the package. Note that the instagram package has a final private function __construct(), this means you cannot use that package outside the original class without changing the construct method to public. I'm not saying this is a good practice, and i suggest to use the scenario 2, in the case of the instagram package.
Anyway, after this you can use the package like this:
$instagramInstance = App::make('Instaphp');
$instagramconfig = array(
'client_id' => 'secret',
'client_secret'=> 'secret',
'access_token' => 'secret'
);
$instagram = new $instagramInstance();
$userfeed = $instagram->Users->feed($instagramconfig);
var_dump($userfeed); // It works!
Add "tvr/googlecheckout": "dev-master" this to your composer.json.
Run composer install, then you can use the IoC container. Some code examples can be found in the official docs for Laravel 4: http://four.laravel.com/docs/ioc#basic-usage

Categories