Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

markMngoma's avatar

Adding Payment Authentication

Hi, I am working on a project, and I am quite stuck here. I don't know what form of authentication to use e.g. Gates, etc. The objective is to develop similar authentication to digital ocean, like when you sign-up with digital ocean. I would like the user to register, but unable to use the admin dashboard without paying a subscription fee and agreeing to the terms and conditions and verifying their account. I would really appreciate your feedback, because I would like to use the most suitable authentication method without wasting any time.

0 likes
4 replies
andonovn's avatar

@markMngoma php artisan make:auth and you have the authentication

Then you need to create a middleware which will check if the user is subscribed and redirect to the subscription page if they are not.

For the subscription page itself you can use Laravel Cashier

For the terms and conditions you can just modify the RegisterController a bit, and of course the blade template.

The account verification at the moment you would need to build manually, but again is very straight forward. By the way, if I am not mistaken Taylor is working on this at the moment and that would be included in the php artisan make:auth in the next release of Laravel.

Hopefully all that makes sense? :)

markMngoma's avatar

It does indeed. I just needed clarity and a point-of-view from another developer. Thanks!

martinbean's avatar

@markMngoma You could create individual route middleware for each prerequisite, and then stack them on the routes that need them. So you could have a middleware class each for:

  • Subscribed
  • Agreed to the terms of service
  • Verified their account

In fact, the Laravel documentation for Cashier has an example of checking the subscription status in middleware: https://laravel.com/docs/5.6/billing#checking-subscription-status

In the other middleware, you can just redirect to the appropriate page. So, for example, agreeing to the terms of services:

class AgreedTerms
{
    public function handle($request, $next)
    {
        if ($request->user()->hasAgreedTerms()) {
            return $next($request);
        }

        // User has not agreed to terms
        return redirect('terms')->withError('You need to agree to the terms of service first.');
    }
}

These middleware classes should then be applied to your routes like this:

Route::middleware(['subscribed', 'agreed_terms', 'verified_email'])->group(function () {
    // These routes will only be accessible if the user:
    // - is subscribed
    // - agreed to the terms of service
    // - and has verified their email address
});

Note: you will need to implement methods yourself, i.e. the hasAgreedTerms() method on the $user object, as I don’t know how you’ve structured your database or how your checking if a user has agreed to your site’s terms or not.

Please or to participate in this conversation.