dongpo2002 2017-10-02 08: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 09: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.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部