Middleware question

Posted 9 months ago by Danieloplata

Hi, I've got an app that I'm making while learning and want to ask how to handle this situation. Apologies if this isn't a middleware thing.

I have a route in my app:

Route::get('/start/{panelid}/{respondentid}', '[email protected]')->name('redirectStart');

This route will basically create a record in my database and then redirect you to a relevant external site.

There are some criteria, where I may wish to prevent the user from being redirected. For example..

// Get users country via API

if(in_array($countrycode, $allowedCountries)) {
    // continue the redirect process
}

I intend to add more checks, such as preventing someone with the same ip/useragent being redirected to the same place twice, and logging it as a duplicate attempt if necessary.

When I've done this before in Vanilla/Procedural PHP, I've just stuck a bunch of if statements before the code I want to run, so I'm a little lost on how I should structure this. If middleware is the way to handle this, should each "check" be it's own middleware?

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