I'm trying to delete city from my db but i really got no clue what to do next. Since I didnt find anything about deleteing data from db for Laravel 8.* I think this might be usefull for other stackoverflowers too.
My error says clearly that I'm missing some arguments,
Too few arguments to function App\Http\Controllers\CityController::delete(), 0 passed in C:\xampp\htdocs\Laravel1\vendor\laravel\framework\src\Illuminate\Routing\Controller.php on line 54 and exactly 1 expected
While my controller says that he expected type 'object' but only found array
Exoected type 'object'. Found 'array'. intelephense(1006)
@var array $todelete
Here is Route from web.php
Route::delete('cities', [App\Http\Controllers\CityController::class, 'delete'])->name('cities.delete');
And this is form I'm using to delete
<form class="float-right m-0" method="post" action="{{ route('cities.delete') }}">
@method('delete')
@csrf
<div class="form-row">
<input type="hidden" name="cityId" value="{{ $city->id }}">
<button> <i class="fa fa-trash-alt"></i></button>
</div>
</form>
Edit
After solving previous problems, I'm stuck on another error:
Call to a member function delete() on array
Here is how my "CityController"s function looks like after updates
public function delete(Request $request)
{
$cityId = $request->get('cityId', false);
// TODO: Check for validation
$todelte = DB::select('select '.$cityId.' from cities');
$todelte -> delete();
return redirect('frontend/city/index');
}
Correct query to delete stuff: DB::table('cities')->where('id', $cityId)-> delete();