I want to update the business hour on the same page. There are other answer that I review in the stackoverflow but I still cannot manage. Help really appreciated.
Model
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class Hour extends Model
{
public $table = 'biz_hour';
protected $primaryKey = 'day_id';
protected $fillable = [
'day_id', 'day_name', 'start_time', 'end_time', 'day_off'
];
public $timestamps = false;
}
Controller
public function update(Request $request, Hour $biz_hour)
{
$request->validate([
'start_time' => 'required',
]);
$start_time = AppModelsHour::find($biz_hour);
['start_time' => $request->start_time];
foreach($biz_hour as $biz_hour){
$start_time->save();
}
return redirect('start_time');
//$biz_hour->update($request->all());
//return redirect()->route('biz_hour.index');
}
Biz_hour.blade.php
<div class="table-responsive">
<table class="table">
<thead class="text-uppercase">
<tr>
<th scope="col">Day</th>
<th scope="col">Start Time</th>
<th scope="col">End Time</th>
<th scope="col">is Day off?</th>
</tr>
</thead>
@foreach($biz_hour as $biz_hour)
<form action="{{ route('biz_hour.update',$biz_hour->day_id) }}" method="POST">
@csrf
@method('PUT')
<tbody>
<tr>
<th scope="row"><br>{{$biz_hour->day_name}}</th>
<td><div class="form-group">
<input class="form-control" type="time" value={{ Carbon::parse($biz_hour->start_time)->format('h:i') }} name="start_time"></div>
</td>
<td><div class="form-group">
<input class="form-control" type="time" value={{$biz_hour->end_time}} name="end_time"></div>
</td>
<td><br><label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="main-content-inner">
<div class="col-lg-6 mt-5">
<button type="submit" class="btn btn-primary mb-3" name="upload">Save</button>
</div>
</div>
</form>
After clicking save button, the page only refresh but the data is not sent to the database. Thanks in advance.