此注释出了什么问题:我正在使用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'));
}
}
感谢您的时间
答案 0 :(得分:1)
通过此控制器,您是否使用了$provinces = Provinces::all();
而未使用模型文件?
例如:Use App\Models\Provinces;