I am using Laravel 5.4 and I am trying to prevent any change in my URL from changing the titles of my dropdown menus.
For example, when I click on one of my dropdown menus, the URL should change (my_site.app/dropdown/
) and the title of the dropdown menu should change to show what item is selected. But the problem I'm running into is I can type anything into the URL and the titles of the dropdown menus change to what is typed in the URL. I want it so that only the proper drop down items can be shown and used, otherwise I want the menus to go to the default 'all'
.
Here is the relevant code from my Controller:
public function setFilters( $request, $defaultFilter=null)
{
if ($defaultFilter) {
$filters['audience'] = 'all';
$filters['category'] = 'all';
return $filters;
}
$isAudience = Audiences::select()->where('type', '=', $request->segment(1))->get();
if ( !empty($isAudience) ) {
$filters['audience'] = strtolower( $request->segment(1) );
}
else {
$filters['audience'] = 'all';
}
if ( !empty($request->segment(2)) ) {
$filters['category'] = strtolower( $request->segment(2) );
}
else {
$filters['category'] = 'all';
}
return $filters;
}
Does anyone know what I can do avoid this issue? And please let me know if any additional information is needed.