5 months ago

Redirect intended not working properly

Posted 5 months ago by zefex

I'm trying to create an age verification system where the user can only see the website after he checks that he agree with the terms, that is what I've done so far:

class AgeController extends Controller
    public function showAcceptanceForm()
        return view('age');

    public function accept(Request $request)
        $request->validate(['terms' => 'accepted']);

        return redirect()
            ->withCookie('terms', true);
class Age
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
    public function handle($request, Closure $next)
        $accepted = $request->cookies->get('terms', false);

        if (! $accepted) {
            return redirect('/age');

        return $next($request);
Route::group(['middleware' => ['age']], function () {
    Route::get('/', function () {
        return view('welcome');

    Auth::routes(['verify' => true]);

    Route::get('/home', '[email protected]')

It's working all fine, the only thing that isn't working is that it's not redirecting the user back to the last page he was (or intended to go), it's always redirecting to /.

What am I doing wrong?

Please sign in or create an account to participate in this conversation.