简体   繁体   中英

"Class 'Nexmo\\Laravel\\Facades\\Nexmo' not found" Error

I am trying to send an sms once a user signs up but it keep getting:

"Class 'Nexmo\\Laravel\\Facades\\Nexmo' not found"

I have this at the top of my controller file:

use Nexmo\Laravel\Facades\Nexmo;

I also have this in my config/app.php file

'Nexmo' => Nexmo\Laravel\Facades\Nexmo::class,

Im still getting an error, does anyone or has the same problem. I know its a class type error but why if I have added the right class and im using it appropriately.

Also, here is my code implementation:

Nexmo::message()->send([
    'to' => '1122334455', //not actually using this number
    'from' => 'Test',
    'text' => 'Hey, test this digit code',
    'text' => $request->user()->activation_token
]);

Update 1: I have done php artisan vendor:publish and published the nexmo config file but it sill gives the error above.

Add Nexmo\\Laravel\\NexmoServiceProvider to the providers array in your config/app.php:

   'providers' => [
    // Other service providers...

    Nexmo\Laravel\NexmoServiceProvider::class,
],

Thanks guys for answers/suggestions

Some reason it is working now? I did all the suggestions/answers and it did not work, did some other stuff (not working on this) and it suddenly works?

Thanks guys :)

If I found out what I did to make it work I will update this answer.

Found the answer: Found out when I run php artisan vendor:publish it gives a list to publish or something and i'm guessing I did not do the one that specifically publishes Nexmo. Still should've worked though because I did the one that will publish everything. Anyways that published the Nexmo file in config folder. Somehow that is what made everything else work, that and probably a combination of answer/suggestions

Anyways thanks guys for your help!!

First of all, the Nexmo documentation did not mention about to use with Laravel but there are as a additional package you need to use if you used with Laravel .

There are are a simple solution.You need to install a additional package that already provide by Nextmo to use with Laravel .Just install below one.I hope this will help u.

composer require nexmo/laravel

try it

            $nexmo = app('Nexmo\Client');

                $nexmo->message()->send([
                    'to' => 'yournumber',
                    'from' => 'yournumber',
                    'text' => "message"
                ]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM