Мое представление (drivers.blade.php) не может идентифицировать переменную из метода индекса DriverController? Моя модель называется Driver.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Driver;
class DriverController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$driver = Driver::all();
return view('drivers', compact('drivers'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
Driver::create($request->all());
return back();
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
Это должно получить все данные из базы данных и затем отобразить их, я пытаюсь создать CRUD, но я всегда получаю эту ошибку "Неопределенная переменная: драйвер (Вид: C: \ xampp \ htdocs \ laravel \ resources \ просмотры \ drivers.blade.php)».
<h2>All Drivers</h2>
<table id="example2" class="table table-responsive" role="grid" aria-describedby="example2_info">
<thead>
<tr>
<th>Fname</th>
<th>Mname</th>
<th>Lname</th>
<th>Phone</th>
<th>Address</th>
<th>Hired</th>
<th>License_no:</th>
</tr>
@foreach($driver as $drive)
<tbody>
<tr>
<td>{{$drive->fname}}</td>
<td>{{$drive->mname}}</td>
<td>{{$drive->lname}}</td>
<td>{{$drive->address}}</td>
<td>{{$drive->hire_date}}</td>
<td>{{$drive->license_no}}</td>
</tr>
</tbody>
@endforeach
</table>