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

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"
]);

Related

Laravel config usage

I have made a config test.php
return [
'name' => 'Testname',
'street' => 'Teststraße',
'street_number' => '69',
'zip' => '42077',
'city' => 'Winterfell',
'telephone' => '0123456789',
'email' => 'hsw#hsw.hsw'
];
created a ConfigServiceProvider:
public function register()
{
config([
'config/test.php'
]);
}
but in my test.blade.php I can access the contents only via
{{config('test.0.name')}}
There has got to be a better, easier way for this right? The data is supposed to be used in multiple blades. Yet the ".0." feels so unnecessary.
I am new to PHP and Laravel, and I am using PHP 8.1 and Laravel 9.14.
Thanks in advance!
#######################
Edit: In my case I had the problem, that my cache wasn't cleared "php artisan config:cache" thanks to #matheenulla for hinting at that!. Thats why I tried the route with the ServiceProvider. I hope this may help someone in the future!
You don't need to create a service provider to use your config, unless you want it to be in some other location (in case you are creating a custom Laravel package), so you may delete your ConfigServiceProvider. In fact, you're just using config wrong:
{{config('test.0.name')}}
should be:
{{config('test.name')}}

Class 'Inline\PDF\PDF' not found in laravel using wemersonjanuario/laravelpdf package

I am trying to use this package -> http://packalyst.com/packages/package/wemersonjanuario/laravelpdf
I have installed and configured as per the website and also I had used this package couple of times which worked following the same procedure.
But now its giving the error Class 'Inline\PDF\PDF' not found
Not sure whats the mistake.
Can someone please help me sort this issue.
Below is the sample code
Composer.json file
"h4cc/wkhtmltopdf-i386": "0.12.3",
"wemersonjanuario/laravelpdf": "1.0.*"
app.php file
'providers' => [
// other providers
Inline\LaravelPDF\PDFServiceProvider::class
],
'aliases' => [
// other aliases
'PDF' => Inline\LaravelPDF\PDFFacade::class,
],
In config/laravelpdf.php file
<?php
return [
'executable' => base_path().'/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386'
];
PHP Pdf code
use Inline\LaravelPDF\PDFFacade as PDF;
class SummaryHelper
{
public function getReport($date)
{
// Some code
$data = [ ]; // some data in it
$pdf_obj = PDF::loadView('vendor/daily-report', $data);
}
}
Github issue link
I've installed the package and got the same error. The thing is it's just a fork from another package and the guy didn't updated readme.md for correct namespaces. What you need to do it to change Inline to Novanti in config/app.php. Both for service provider and facade.
Then add this to the class where you want to use PDF facade:
use PDF;
Or just use full namespace:
$pdf_obj = \PDF::loadView('vendor/daily-report', $data);
Sorry for this.
I have changed the namespace to Novanti instead of Inline.
Please switch to 1.1.* version and change alias and provider namespaces to Novanti.
I have also updated the README.md to better document this.
Let me know if this works.
Thank you for reporting.

Laravel 5.1 GuzzleHttp Client error: 404 when using mailgun

I'm using the Mailgun service when sending mail with Laravel. However, i've set this up today and it's just stopped working. I have entered all the correct info in .env, config/services.php and config/mail.php. However i'm still getting the below error:
ClientException in Middleware.php line 69:
Client error: 404
It looks like the domain is not getting passed through somehow, even though in my config/services.php file I have:
'mailgun' => [
'domain' => env('mydomain.com'),
'secret' => env('<my-mailgun-key>'),
],
I have hidden the above credentials for safety, but in my real application they are the proper values.
Please help.
I was having a very similar 404 issue and tried the solution mentioned by Rogério. I thought I was doing it right, but gave it a try anyway. But misuse of the env() function wasn't my problem.
I set the config/services.php back to look like so:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN',''),
'secret' => env('MAILGUN_SECRET',''),
],
This will provide empty strings if the values named MAILGUN_DOMAIN and MAILGUN_SECRET are not found in the .env file. Then, in my .env file, I included the API Base URL and API Key from the Mailgun domain information page. So the .env looked something like this:
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox123abc.mailgun.org
MAILGUN_SECRET=key-123456abcdef
The values were passing along as they should, but still 404. Looking at How do I start sending email documentation at Mailgun, I saw that their API URL included "messages" on the end - which I tried manually adding to the .env setting:
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox123abc.mailgun.org/messages
That didn't work either, but lead me to look more carefully at the stack trace spit out by Laravel. That's when I noticed that the URL it was trying to connect with was:
https://api.mailgun.net/v3https://api.mailgun.net/v3/sandbox123abc.mailgun.org/messages/messages.mime
Ah-ha! Using Mailgun's Base API URL was incorrect! That was made obvious by the repetition of the "https://api.mailgun.net/v3" portion. So the aptly named MAILGUN_DOMAIN setting really just needed to be:
MAILGUN_DOMAIN=sandbox123abc.mailgun.org
Seems obvious now, but I spent way too much time figuring it out. Thought I'd put it out there in case anyone else happened to miss that detail
I hade the same problem as you and solved it by removing the env() call.
Thats because env will return the value of the env variable in the first argument (not the value of the argument) and otherwise return the second argument.
So:
'mailgun' => [
'domain' => 'mydomain.com',
'secret' => '<my-mailgun-key>',
],
Try that.

YII2 application working on local but PAGE NOT FOUND error on live

I have created a simple application in YII2 and it is working fine at my local machine but giving me Not Found (#404) "Page Not Found" error on live server.
Local URL: http://localhost:8080/basicapp/web/index.php?r=adminPanel%2Fstatemaster%2Findex
Live URL: http://XXXX.com/web/index.php?r=adminPanel%2Fstatemaster%2Findex
I am not using pretty URL, and didn't change in web.php. just added module info in the file. Code Snippet:
'modules' => [
'adminpanel' => [
'class' => 'app\admin\adminpanel',
],
'studentPanel' => [
'class' => 'app\Student\dashboard',
],
],
I can provide detial, whatever is required.
If anyone have similar problem, Just change your naming of models and controllers.
In my problem, model and controller names were like StateMasterController etc but it should be StatemasterController, mind the M.
It works for me, may be this can help you.
Thanks

Unable to generate a Cashier PDF in Laravel

I am using Laravel 5 to generate a PDF from a subscription generated from Cashier. The docs say this is as simple as calling:
return $user->downloadInvoice($invoice->id, [
'vendor' => 'Your Company',
'product' => 'Your Product',
]);
Unfortunately I'm getting an odd error:
No hint path defined for [cashier]
The code I am actually using is as follows:
Route::get('billing/invoices/download/{id}', function($id){
$user = Auth::user();
//$invoice = $user->invoices()->find($id);
return $user->downloadInvoice($id, [
'vendor' => 'Certify Me',
//'product' => $invoice->lines->data[0]['plan']->name,
'product' => 'Subscription',
]);
});
The docs make me assume that the PDF is automatically generated. I'd then assume I could override the PDF layout if I chose to.
I just ran into this (L5.1, Cashier 6.0). This seems to be caused by the service provider not being correctly loaded.
Here is how I fixed it:
Check that you have added the correct service provider, at the time of writing that is Laravel\Cashier\CashierServiceProvider to your config/app.php
If it still doesn't work, go run php artisan config:clear to make sure that the service provider is picked up.
Happy invoicing!
I'm going to resurrect this beast.
I had a similar issue because the service provider was not loaded. If you checkout CashierServiceProvider you'll see it adds the necessary 'namespace' for the 'cashier' prefixed views.
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'cashier');
$this->publishes([
__DIR__.'/../../views' => base_path('resources/views/vendor/cashier'),
]);
}
Add Laravel\Cashier\CashierServiceProvider to your config/app.php file and inside the providers key.
For anyone who runs across this like we did.

Categories