【问题标题】:ErrorException (E_ERROR) Undefined variable: buildingSectionsErrorException (E_ERROR) 未定义变量:buildingSections
【发布时间】:2018-11-29 18:39:17
【问题描述】:

我试图从一个页面存储到数据库中,我传递了一个变量,该变量使用 @foreach 显示良好,没有上述错误,但是当它被保存时,它给出了上述错误。 这是控制器

$this->validate($request, array(
        'building_section' => 'required',
        'reported_date' => 'required',
        'fault' => 'required',
    ));
    $maintenance = New Maintenance();
    $maintenance->tenants_id = AssetTenant::where('tenant_id', '=', \Auth::user()->id)->first();
    $maintenance->category = AssetTenant::where('description', '=', $maintenance->tenants_id);
    $maintenance->building_section = $request->building_section;
    $maintenance->reported_date = $request->reported_date;
    $maintenance->fault = $request->fault;
    //Flash Message
    $request->session()->flash('success', 'Tenant successfully Added');
    //redirect
    return view('/tenant/addMaintenance');

视图

<select type="text" class="form-control" name="building_section" required="">
                            @foreach($buildingSections as $section)
                                <option >{{ $section->section }}</option>
                            @endforeach
                        </select>

注意:此代码在其他部分运行良好。

我错过了什么?

【问题讨论】:

    标签: mysql laravel compiler-errors


    【解决方案1】:

    我想这是因为您正在返回视图而不是重定向到该页面:

    改变:

    return view('/tenant/addMaintenance');
    

    到:

    return redirect('tenant/addMaintenance');
    

    【讨论】:

      猜你喜欢
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多