I created my model with this command php artisan make:model BuildingOnRent -mcr which created the controller and the resources.
In my web.php, I passed the resource route like this
My web.php
Route::resource('br', BuildingOnRentController::class);
In the controller scaffolded by Laravel herself, I added the code under the update function like this.
My controller
public function update(Request $request, BuildingOnRent $br)
{
echo $br;
$request->validate([
'purpose'=>'required',
'rooms'=>'required',
'bathrooms'=>'required',
'parlour'=>'required',
'rent_period'=>'required',
'cost'=>'required',
'city'=>'required',
'state'=>'required',
'locate'=>'required',
]);
dd($br);
$br->update($request->all());
return redirect()->route('br.index')->with('success','Property updated successfully');
}
My edit.blade form action
action="{{ route('br.update',['br'=>$br]) }}"
When I fill and submit the form in the edit.blade, hence triggering the update function in the controller, I am redirected to the route br.index but nothing is updated. In fact, the update code is not even run as I tried to echo $br and dd($br) but nothing was echoed or dumped. I take it that the update code is not run at all.
Why is the update code block not run?
How can I make it to run?
I am using laravel 10. Please help out.