Support the ongoing development of Laravel.io →
Database Eloquent

Hey,

I'm trying to remove a record by unquie id using eloquent this is my first ever project in laravel so I'm still trying to learn! Currently when I click delete it removes all the records not the one where ID = x

Route::post('/status/{statusId}/delete', [
'uses' => '\Dashboard\Http\Controllers\StatusController@deleteStatus',
'as' => 'status.delete',
'middleware' => ['auth'],
]);

public function deleteStatus(Request $request, $statusId)
{
    Auth::user()->statuses()->delete('{$statusId}');

return redirect()->route('home')->with('success', 'Post deleted.');
}
Last updated 3 years ago.
0

Try to use:

Auth::user()->statuses()->find('{$statusId}')->delete();

Hope it works!

PS: If you are starting with Laravel I can recommend you a Laravel step-by-step course: Learn Laravel 5.0 => 5.1

Best wishes.

Last updated 9 years ago.
0

If it's a unique ID, why do you even need the user?

Status::destroy($id);
0

thomastkim said:

If it's a unique ID, why do you even need the user?

Status::destroy($id);

if you have a unique id, you only need to use the destroy method of 'Status' model

0

Sign in to participate in this thread!

Eventy

Your banner here too?

xron89 xron89 Joined 16 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.