Call to a member function paddleOptions() on null

32 Views Asked by At

i want to integrate with paddle payment but will 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>

1

There are 1 best solutions below

0
Jeyhun Rashidov On

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');
}