My view(drivers.blade.php) cannot identify a variable from DriverController index method? My model name is 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)
{
//
}
}
This should get all the data from the database and then display them, i'm trying to create a CRUD but i always get this error "Undefined variable: driver (View: C:\xampp\htdocs\laravel\resources\views\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></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
@endforeach
</table>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire