I'm working on a Laravel 5.2 project and I have users ,flags and countrys. What im trying to achieve is that each user can click on the Flag menu, and it should present a list of flags for the country the user is in.
so User has country_id
Flags have country_id.
at the moment I can show the flags for each user and theyr respective country.
Here is the route.
Route::get('flags/{Country_id}','FlagController@showFlags');
the view
<a href="flags/{{Auth::user()->country_id}}">
and my controller
public function showFlags($id)
{
$country = new Country;
$country = $country->find($id);
$flags = $country->flags;
return view('layouts.f.mainf',compact('flags'));
}
The problem is, if i change the county id on the url to anything else, it will show the flags of another country, how can I restric that it can only be acessible if the users country matches the url country id? I've read something about middleware but to be honest Im not sure how to use it.