I'm having a problem with my Huntercontroller functions: store(), update() and destroy() display the following error message: Undefined variable $hunter on the index.blade.php page.
On the index.blade.php page, the error that appears is the following:
<?php $__currentLoopData = $hunter; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $hxh): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
Since this line points to a @foreach($hunter as $hxh) to view the database records. I don't understand why this is happening, update() and destroy() even with this problem I realize that they run, I just don't say the same about store().
web.php
Route::controller(HunterController::class)->group(function () {
Route::get('/', 'index');
Route::get('/create', 'create');
Route::get('/update/{id}', 'edit');
Route::post('create', 'store');
Route::patch('/update/{id}', 'update');
Route::delete('/delete/{id}', 'destroy');
});
HunterController.php
public function store(Request $request)
{
$validations = $request->validate(
[
'name_hunter' => 'required|max:50',
'year_hunter' => 'required|numeric',
'height_hunter' => 'required|numeric',
'weight_hunter' => 'required|numeric',
'type_hunter' => 'required|max:30',
'type_nen' => 'required|max:30',
'type_blood' => 'required|max:3',
]);
HunterModel::saved($validations);
return view('index');
}
public function update(Request $request, $id)
{
$validations = $request->validate(
[
'name_hunter' => 'required|max:50',
'year_hunter' => 'required|numeric',
'height_hunter' => 'required|numeric',
'weight_hunter' => 'required|numeric',
'type_hunter' => 'required|max:30',
'type_nen' => 'required|max:30',
'type_blood' => 'required|max:3',
]);
HunterModel::where('id',$id)->update($validations);
return view ('index');
}
public function destroy($id)
{
HunterModel::where('id',$id)->delete();
return view('index');
}