It's easier to create another middleware, something like this:
namespace App\Http\Middleware;
use Closure;
class CountryCheck
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// The method `getEnabledCountries` returns an array
// with the countries enabled for the user
if(in_array($request->route('country'), Auth::user()->getEnabledCountries())) {
return $next($request);
}
// abort or return what you prefer
}
}
Anyway... the country
parameter is useless in my advice if the user can see only posts from his country... If you already know the user locale and you already have this rule... why you have to made another check?
In my opinion it's better to create a route like Route::get('posts')
and inside the controller load the posts related to the user's country... Something like:
Post::where('locale', '=', Auth::user()->locale())->get()
or with a scope:
Post::whereLocale(Auth::user()->locale())->get()