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

Posted

技术标签:

【中文标题】路由未定义视图:E:\\xampp\\htdocs\\offices\\resources\\views\\admin\\offices\\create.blade.php 错误【英文标题】:Route not define View: E:\xampp\htdocs\offices\resources\views\admin\offices\create.blade.php ERROR路由未定义视图:E:\xampp\htdocs\offices\resources\views\admin\offices\create.blade.php 错误 【发布时间】:2019-07-12 14:21:30 【问题描述】:

我正在做一个项目,我想在其中保存办公室地址,并且办公室 create.blade 具有依赖于国家和城市的下拉列表,我使用 javascript 进行 AJAX 调用,但是当我正在运行它,我收到“在 office.create.blade 中路由未定义错误。

下面是office.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 代码

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 代码

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');
    

在 web.php 中定义路由如下

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

我不知道我在哪里做错了? 期待帮我扔这个 谢谢

【问题讨论】:

【参考方案1】:

您可以先尝试使用原始网址,但请确保在网址之前指定前斜杠,如下所示:/cities/get_by_country。

这会将 url 视为基于根的。

【讨论】:

以上是关于路由未定义视图:E:\xampp\htdocs\offices\resources\views\admin\offices\create.blade.php 错误的主要内容,如果未能解决你的问题,请参考以下文章

Vue 组件未在路由器视图中呈现

未找到 Laravel 注册索引并创建错误

laravel刀片视图中的变量未定义错误

Local.ERROR:未定义路由 [登录]。 Laravel 问题

路线 [课程] 未定义

VueJS 3 / 路由器 / 带有推送的重定向:未捕获(承诺中)类型错误:无法读取未定义的属性(读取“推送”)