Hey Im trying to delete a record in laravel but I get this error: Undefined variable: row (View: C:\xampp\htdocs\Laravel\laravel\resources\views\admin\addEmployee.blade.php) at this row : <form action="/deleteEmployee/" method="POST">
Here is full HTML code What might be possibly going wrong?
<tbody>
<!-- Displaying all the employees from the database -->
@foreach($users as $user)
@if($user->is_admin !== 1)
<tr>
<td> </td>
<td> </td>
<td> $</td>
<td> </td>
<td>
<a href="/editEmployee" class="btn btn-success">EDIT</a>
</td>
<td>
<form action="deleteEmployee/" method="POST">
<button type="submit" class="btn btn-danger">DELETE</button>
</form>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
Controller
class DashboardController extends Controller
{
//Add employee function in admin dashboard
public function addEmployee()
{
$users = User::all();
return view('admin.addEmployee')->with('users',$users);
//return view('adminHome');
}
public function editEmployee(Request $request, $id)
{
$users = User::findOrFail($id);
return view('admin.editEmployee')->with('users',$users);
//return view('adminHome');
}
public function updateEmployee(Request $request, $id)
{
$users = User::find($id);
$users -> name = $request -> input('name');
$users->email = $request->input('email');
$users->salary = $request->input('salary');
$users->department = $request->input('department');
$users->update();
return redirect('admin/addEmployee')->with('status','Employee record is updated');
}
public function deleteEmployee( $id)
{
$users = User::findOrFail($id);
$users -> delete();
return redirect('addEmployee')->with('status','Employee record is deleted');
}
}
Route
Route::delete('/deleteEmployee/{id}','Admin\DashboardController@deleteEmployee');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire