dongpo2002 2017-10-02 16:58
浏览 55
已采纳

Laravel 5.4 - 如何防止我的URL更改更改我的下拉菜单的标题?

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.

  • 写回答

1条回答 默认 最新

  • douqian2957 2017-10-02 17:20
    关注

    My suggestion is to create a controller for those links, like PagesController and do if statement to control the urls. In the tags specify the dropdown option and do if statements for each URL, and else statement to throw any errors un case someone type the option in the URL directly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?