dongzhuang6417 2016-09-07 13:54
浏览 79
已采纳

Laravel 5.2路由,可选参数不起作用

i just can't seem to find the problem, hope someone can help me.

Im trying to reach my controller, and then use my parameter, but it alwasy says its missing the parameter.

Route file:

Route::get('admin/site-settings/global-data/{part?}/', ['as' => 'admin/global-data-edit', 'uses' => 'admin\GlobalDatasController@getGlobalData']);

Function:

    public function getGlobalData(Request $request, $part){

    $globalData = GlobalData::find(1);

    switch ($part){

        case "content":

            if($request->ajax()){
                return view('admin.site-settings.global-data._ajax_load_content', compact('globalData'));
            }

            return view('admin.site-settings.global-data.edit')->with('globalData', $globalData);

            break;

        case "logo":

            if($request->ajax()){
                return view('admin.site-settings.global-data._ajax_load_logo', compact('globalData'));
            }

            return view('admin.site-settings.global-data.edit')->with('globalData', $globalData);

            break;
    }


}

AND my View:

        function load_data() {
        $('#load-data').hide().html('<div class="loader"><i class="fa fa-spinner" aria-hidden="true"></i></div>').fadeIn();
        var url = '{{route('admin/global-data-edit')}}';
        $.ajax({
            url: url,
            type: "GET",
            success: function(data){
                $data = $(data);
                $('#load-data').hide().html($data).fadeIn();
            }
        });
    }

Thank you so muych for your time in advance!

Best regards.

  • 写回答

1条回答 默认 最新

  • douwen3083 2016-09-07 14:07
    关注

    Change:

    public function getGlobalData(Request $request, $part){
    

    to:

    public function getGlobalData(Request $request, $part = null){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?