My code is:
settings.blade.php (blade):
<form method="POST" action="{{route('user.settings', $apartment->apartment_id)}}">
@method('delete')
@csrf
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
</form>
UserController.php:
public function delete(Apartment $apartment)
{
$apartment->delete();
return redirect()->route('dashboards.users.index')
->withSuccess(__('Deleted successfully'));
}
web.php:
//Authorization based on user role
Route::group(['prefix'=>'user', 'middleware'=>['isUser','auth','PreventBackHistory']], function(){
Route::get('dashboard',[UserController::class,'index'])->name('user.dashboard');
Route::delete('settings/{apartment}',[UserController::class,'delete'])->name('settings.delete');
Route::resource('settings','UserController@delete')->name('user.settings');
Route::get('profile',[UserController::class,'profile'])->name('user.profile');
Route::get('settings',[UserController::class,'settings'])->name('user.settings');
});
Could someone please help?
2
Answers
Use route model binding
Then
You are re-routing the settings again using resource. Rename ‘resource’ to ‘get’
Keep the same route and form.