duano3557 2019-02-18 22:39
浏览 66
已采纳

路由未定义视图:E:\ xampp \ htdocs \ offices esources \ views \ admin \ offices \ create.blade.php错误

I am working on a project in which I want to save addresses of offices and the offices create.blade have country and city dependent drop-down for dependent drop-down I did the following code using JavaScript for AJAX call, but when I am running it, I am getting "Route not define error in office.create.blade.

Below is the for offices.create.blade

@section('scripts')
        <script type="text/javascript">
            $("#country").change(function(){
                $.ajax({
                    url: "{{ route('admin.cities.get_by_country') }}?country_id=" + $(this).val(),
                    method: 'GET',
                    success: function(data) {
                        $('#city').html(data.html);
                    }
                });
            });
        </script>
    @endsection
<div class="panel panel-default">
        <div class="panel-heading">
            @lang('quickadmin.qa_create')
        </div>
        
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('country_id', trans('quickadmin.offices.fields.country').'*', ['class' => 'control-label']) !!}
                    {!! Form::select('country_id', $countries, old('country_id'), ['class' => 'form-control select2', 'required' => '']) !!}
                    <p class="help-block"></p>
                    @if($errors->has('country_id'))
                        <p class="help-block">
                            {{ $errors->first('country_id') }}
                        </p>
                    @endif
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('city_id', trans('quickadmin.offices.fields.city').'*', ['class' => 'control-label']) !!}
                    <select name="city_id" id="city" class="form-control">
                    <option value="">{{ trans('quickadmin.qa_please_select') }}</option>
                </select>
                    <p class="help-block"></p>
                    @if($errors->has('city_id'))
                        <p class="help-block">
                            {{ $errors->first('city_id') }}
                        </p>
                    @endif
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('address', trans('quickadmin.offices.fields.address').'*', ['class' => 'control-label']) !!}
                    {!! Form::text('address', old('address'), ['class' => 'form-control', 'placeholder' => '', 'required' => '']) !!}
                    <p class="help-block"></p>
                    @if($errors->has('address'))
                        <p class="help-block">
                            {{ $errors->first('address') }}
                        </p>
                    @endif
                </div>
            </div>
            
        </div>
    </div>

CitiesController.php code

public function get_by_country(Request $request)
    {
        abort_unless(\Gate::allows('city_access'), 401);

        if (!$request->country_id) {
            $html = '<option value="">'.trans('quickadmin.qa_please_select').'</option>';
        } else {
            $html = '';
            $cities = City::where('country_id', $request->country_id)->get();
            foreach ($cities as $city) {
                $html .= '<option value="'.$city->id.'">'.$city->name.'</option>';
            }
        }

        return response()->json(['html' => $html]);
    }

OfficeController.php code

public function perma_del($id)
    {
        if (! Gate::allows('office_delete')) {
            return abort(401);
        }
        $office = Office::onlyTrashed()->findOrFail($id);
        $office->forceDelete();

        return redirect()->route('admin.offices.index');
    }

define route in web.php as below

Route::get('cities/get_by_country', 'CitiesController@get_by_country')->name('admin.cities.get_by_country');

I don't know where I did mistake? looking forward for helping me throw this Thanks

</div>

展开全部

  • 写回答

1条回答 默认 最新

  • dongqie2355 2019-02-18 23:32
    关注

    You can try to use raw url first but make sure you specify fore slash before the url like this: /cities/get_by_country.

    This treats the url as root based.

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

报告相同问题?

悬赏问题

  • ¥20 MC9S12XS128单片机开发板实验,
  • ¥15 C#多线程假死或卡死问题
  • ¥15 关于#tcp/ip#的问题:苹果电脑M1,easyconnect登录成功,显示虚拟 IP 地址
  • ¥15 客户端发现不了OPC服务器
  • ¥35 spaceclaim脚本
  • ¥500 寻找华为新款路由器开telnet方法
  • ¥20 运行pointnerf模型遇到了pycuda的错误,如何解决?(相关搜索:测试代码|自动驾驶|数据集)
  • ¥15 失败的github程序安装
  • ¥15 WSL上下载的joern在windows怎么用?
  • ¥15 jetson nano4GB
手机看
程序员都在用的中文IT技术交流社区

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

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

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

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

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

客服 返回
顶部