How do I import Twilio in Laravel? - laravel

How do I import the Twilio library in Laravel Controller?
I tried several ways of importing in but it does not work
FatalErrorException in TwilioController.php line 13:
Class 'App\Http\Controllers\Services_Twilio' not found

Have you tried to install via composer? The docs seem pretty straight forward.
composer require twilio/sdk
Then you'd initiate the Twilio class in your app. Like so:
$client = new \Services_Twilio($AccountSid, $AuthToken);
Because Laravel is uses namespaces, you'll need to make sure the class reference is pointed to the correct namespace. By adding the \ before Services_Twilio you are referencing the global namespace. You can also use a use statement at the top of your file to reference the Twilio class, so you don't need the \. Here is a good reference on namespaces

Related

how to import and use Pear XML serializer in Laravel project

I am trying to use Pear XMLSerializer package ina Laravel project.
I have included the in composer.json and did composer install and composer update.
Now how to i call it and use it in a class - what use statement I should use at top of class to use it in the class?
Thanks
I spent a quite long time in order to get it work, but I couldn't, I found "StreamParser", It gave me the same functionality, https://laravel-news.com/php-7-multi-format-streaming-parser. hopefully, it will help you.

Laravel mailChimp package error

I try to use the package https://github.com/BlueBayTravel/Mailchimp as in examples but i got an error:
ErrorException in Mailchimp.php line 64:
Undefined property: BlueBayTravel\Mailchimp\Facades\Mailchimp::$users
when i try to use: Mailchimp::users(), while i can get a connection via Mailchimp::getDefaultConnection(); mean the package is completely red, what u guess the problem with me here ?
I saw that you already opened an issue in the package repo.
If you are using Laravel, and you want to use an existing integration with Mailchimp, I would recommend you to give a try to the spatie/laravel-newsletter package. It's the most complete package I've found for the integration Laravel + Mailchimp, and it uses the drewm/mailchimp-api API wrapper (which IMO, is the best php wrapper for Mailchimp). You can find some examples at Freek's blog or at the README file of the project. And if you do not find what you need, you can go to a lower level using the drewm wrapper: $api = Newsletter::getApi();
If this is not what you are looking for, you can always create your own service in Laravel, adapted to your needs and requierements ;)

Loading composer package into Laravel 5.2

I am trying to add the following package to my Laravel 5.2 project. At the top of my class I have added
use PhpImap\Mailbox as ImapMailbox;
use PhpImap\IncomingMail;
use PhpImap\IncomingMailAttachment;
I then do something like this
$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/ssl}INBOX', 'some#gmail.com', '*********', __DIR__);
At the moment, when I visit the page I get
Class 'PhpImap\Mailbox' not found
I have tried many different ways to load it with the same result. Because this package is not Laravel specific, I don't know if I need to add anything else? Normally when I add Laravel packages I create a provider and alias, do I need to do that here?
Any information appreciated.
Thanks

Laravel 5 Twilio Namepace

I am implementing Twilio in Laravel 5, the tutorial I am using is very good https://www.twilio.com/blog/2014/09/getting-started-with-twilio-and-the-laravel-framework-for-php.html.
Do you know what the namespace is for laravel 5?
I am getting
Class 'Services_Twilio_Twiml' not found
Thanks
If you install the twilio/sdk package via composer you should have access to all the Twilio classes automatically, since laravel uses composer's autoloading.
They are not really namespaced. You would use \Services_Twilio_Twiml.
You can tell composer to load your Twilio folder by adding :
"autoload" : {
"classmap" : [ "your/Twilio/folder" ]
}
to your composer.json
If I understood you clearly you have put your Twilio code in a given file and you are getting this error saying "Class 'Services_Twilio_Twiml' not found".
I am writing here possible reason you are getting this.
/config/services.php- you have not added Twilio details which are
i. sid
ii. token
iii. from
in file in which you have integrated your Twilio code, you have to ensure to write use Twilio;
In your app.php you have to add in providers section Twilio which you are using for example: 'Aloha\Twilio\TwilioServiceProvider'
and aliases section 'Twilio' => 'Aloha\Twilio\Facades\Twilio',.
If you look at this you might find answer.
For Laravel 5 (and older Laravel 4 applications) I suggest using the aloha/twilio package. It provides some code samples in the readme file that should help you get going quickly. One can inject a configured object using the TwilioInterface type hint which has methods to send SMSs MMs and calls.

Is there any good sample about facebook-php-sdk3.0+ with CodeIgniter2.0+?

I use CodeIgniter2.0.3 and facebook-php-sdk3.1.1 to develop an application.
When I run the project,is says:
Fatal error: Cannot redeclare class Facebook in ../application/libraries/facebook.php on line 24
The source of line 24 is:
class Facebook extends BaseFacebook
What's the reason?How to deal with it?
Check the name of your controller. If it is called Facebook then that is your problem, you cannot have 2 classes called the same thing at once, unless they are in different namespaces.
I wouldn't suggest using the normal Facebook PHP-SDK when there are a number available over on codeigniter sparks that perform most of the same functions but already setup to work with codeigniter without these conflicts.

Resources