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.
Related
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')}}
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"
]);
I defined an option in my website named "define user". So I need to do some changes in the current laravel registration system. Actually I did what I need:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
if ( !isset($request->registered_by_id) ) { -- added
$this->guard()->login($user);
$status = ""; -- added
$msg = ""; -- added
} else { -- added
$status = "define-user-alert-success"; -- added
$msg = "the user registered successfully";
} -- added
return $this->registered($request, $user)
?: redirect($this->redirectPath())
->with($status, $msg); -- added
}
As you know, function above is located under /vendor/laravel/framework/src/illuminate/Foundation/Auth/RegisterUsers.php path. The problem is all the change I made will be ignored when I upload my website and execute composer install command.
Any idea how can I keep my changes in the vendor directory?
composer install will overwrite your changes as it just fetches the latest version from the public repo and installs that.
I would suggest one of the following;
Create your own fork of laravel and have composer load this over default laravel. I did this recently with a Symfony component fork, the idea is to change the repo branch name to your modified one and override the source with your own repo. Instruction from my fork are here.
Upload the file manually via after executing composer install (not recommended, only use a stop-gap).
Override/extend the original class, this answer lays out the process nicely.
As defined in this answer on Laracasts (which is very similar to your case), use event listeners to execute your code after user registration.
Hope this helps!
I would strongly recommend against making any changes to the core framework - aside from the issue you mentioned, it can also make upgrades extremely difficult.
Fortunately, Laravel makes user registrations easy. All you need to do is create a new controller (E.g. UserController) and then use a function like this to create a model for them ...
public function registerUser(Request $request){
$request->validate([
'username' => 'bail|required|unique:users,username|max:255',
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required|email'
]);
$user = User::create([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'username' => $request->username,
'password' => Hash::make($request->password),
'email' => $request->email
]);
return redirect('/settings/people/'.$user->user_id);
}
The key here is to use the hash facade to encrypt the password before committing the model to the database. Otherwise, it's essentially like working with any other model.
Yea, don't edit the file in vendor.
This trait is used in the RegisterController which exists in your app, not the framework. You can simply override that method in your controller, done.
Perhaps your changes can go in registered which is called after registration so you don't have to override this functionality of register itself (since registered is a blank method waiting to be overridden)
I am trying to implement this library for sending push notifications to iOS app. All my configurations are fine. When I tested the code snippet available at this page like this:
PushNotification::app('appNameIOS')
->to($deviceToken)
->send('Hello World, i`m a push message');
It threw this error:
Non-static method
Davibennun\LaravelPushNotification\PushNotification::Message() should
not be called statically
Rightly so, because when I opened the class, there was no such static method. There is one but that is not static. What am I doing wrong? Any help?
Edit 1
I have generated config file:
return array(
'hasalty_ios' => array(
'environment' =>'development',
'certificate' =>base_path('pem.p12'),
'passPhrase' =>'',
'service' =>'apns'
),
'hasalty_android' => array(
'environment' =>'production',
'apiKey' =>'yourAPIKey',
'service' =>'gcm'
)
);
Edit 2
My Laravel version is 5.5.31.
If you configure the library correctly, you should use
use Pushnotification;
instead of
use Davibennun\LaravelPushNotification\PushNotification;
When a user references any static method on the Cache facade, Laravel resolves the cache binding from the service container and runs the requested method (in this case, get) against that object.
How Facades Work
Edit
You must generate the config file before you use it:
php artisan vendor:publish --provider="Davibennun\LaravelPushNotification\LaravelPushNotificationServiceProvider" --tag="config"
Try to use this code:
Change here use Pushnotification instead
of use Davibennun\LaravelPushNotification\PushNotification;
I am trying to implement JWT token in my API using Lumen + JWT. I am using this JWT Library, I have set up it, but when I want to validate passed using JWTAuth::attempt($credentials) I get next error
ErrorException in AuthManager.php line 16:
Missing argument 1 for Illuminate\Auth\AuthManager::createDriver(), called in /home/admin/web/mkopilka.ru/public_html/api/referral/vendor/illuminate/support/Manager.php on line 87 and defined
I know where is the problem, but cannot figure out how to solve it because I don't know internals of framework well.
I have question about how does JWT authenticate the user (checks credentials in database, as I can gues it uses model class provided in jwt.php with the following line 'user' => 'App\Models\User'
By default 'user' => 'App\User'
So even if I changed user model in this file I got the next error
vendor/illuminate/auth/EloquentUserProvider.php line 126:
Class '\App\User' not found
I thought and decided to add config/auth.php file with succeeding content
return [
'model' => 'App\Models\User'
];
And now I get the the first exception.
What is wrong I can quess that I have overridden all parameters in auth config file.
Aslo I wonder where can I find (except source code, it will take a lot of time to understand it) explanation how JWTAuth::attempt works ?
Thanks.
Just had same issue myself and stumbled upon this question.
Solution is to add 'driver' => 'eloquent' into your created auth.php file.
I had the same problem on my upgrade from Laravel 4.1 to 4.2 (I think mainly because I updated all the files and tried to make a composer update afterwards).
For me the following worked (like reverting the relevant update steps):
1. Modify auth.php
Add driver, model and table to config/auth.php main array (additionally to the already existing one in the providers sub array):
<?php
return [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'users',
// ...
2. Add ArtisanServiceProvider
To prevent the error Artisan: Command clear-compiled is not defined readd Illuminate\Foundation\Providers\ArtisanServiceProvider to the service providers
<?php
return [
// ...
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
// ...
3. Update and revert changes
Perform update (composer update) and revert the two previous steps by removing the added lines.