未定义的变量:省份(视图:E:\ XXXXXXXXXXX \ create.blade.php)

时间:2018-07-02 17:16:44

标签: laravel-5.6

此注释出了什么问题:我正在使用Laravel 5.6 我的猜测是“ @foreach”

出了点问题

<div class="form-group">
                                   @foreach ($provinces as $key => $value)
                                 <label for="">Your Provinces</label>
                                  <select class="form-control" name="provinces" id="provinces">
                                   <option value="0" disable="true" selected="true">=== Select Provinces ===</option>
                                 <option value="{{$value->id}}">{{ $value->name }}</option>
                                    
                                    </select>
                                        </div>
                                     @endforeach

it tells me undefined variable provinces and here is my Controller 


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\View;

class CountryController extends Controller
{
   
    public function provinces(){
      $provinces = Provinces::all();
      return view('posts.create', compact('provinces'));
    }
}

感谢您的时间

1 个答案:

答案 0 :(得分:1)

通过此控制器,您是否使用了$provinces = Provinces::all();而未使用模型文件?

例如:Use App\Models\Provinces;