0

I need to implement something particular for registration page.

I send to users a link like this:

https://mywebsite.com/register?id=123456789

Then, i check to my database if the ID exists, and if not, i want to redirect the user to another page, and they cannot subscribe to my website.

What is the best way to do this? I cannot find a valid solution...

I tried do modify the file App\Http\Controllers\Auth\RegisterController.php (__construct method) but nothing happens.

Thanks in advance for help!

pasluc74669
  • 1,680
  • 2
  • 25
  • 53

1 Answers1

0

If I understand this right, you want to create a referral only registration. Things like this would be ideally implemented to middleware so you could go with something like this.

<?php

namespace App\Http\Middleware;

use Closure;
use App\User;

class Referred
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (!User::find(request()->id)) {
            return redirect()->to('find-a-sponsor-error-page');
        }

        return $next($request);
    }
}

then just add the middleware to your registration route