Reputation: 9
I want to integrate with paddle payment but when I run this code I got this error Call to a member function paddleOptions() on null
This my controller
try {
$paylink = Auth::user()->charge(50.0, 'Premium');
dd($paylink);
return view('admin.payment.test', [
'paylink' => $paylink,
]);
} catch (\Exception $e) {
echo $e->getMessage();
}
this blade
<a href="{{ $paylink }}">Pay</a>
Upvotes: -1
Views: 57
Reputation: 1128
If the user is not authenticated, Auth::user()
will return null. So, when trying to call the charge method on null, you'll encounter this error. Make sure that you have used middleware for this route to make it available only for authed users:
Route::get('/payment-url', 'PaymentController@paymentMethod')->middleware('auth');
Or you can simply add this code to your top of method in controller:
if (!Auth::check()) {
return redirect('login')->with('error', 'Please login to continue');
}
Upvotes: 0