0

I'm trying to delete table row by table cell ID.

I have a table called "server_admins". With table cell unique ID.

public function admins_delete($id)
{
    $serveradmins = DB::table('server_admins')->first();
    $serveradmins->delete($id);
    return Redirect::to("/admin/servers/admins");
}

Route:

ModuleRoute::post('admin/servers/admins/delete/{id}', 'AdminServersController@admins_delete');

And my view:

<a href="/admin/servers/admin/delete/{!! $serveradmin->id !!}"></a>

But does not work at all... Any info? I'm new with laravel, so im kind a noob on that :) Sorry for dumb ask and thanks for helping me understand laravel.

2 Answers 2

1

Try this

Model::where('id',$id)->delete();; // Eloquent approach

DB::table('server_admins')->where('id',$id)->delete(); // Query Builder approach
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, relaly fast answer! Thank u so much!
1

You can directly chain like this if you know the primary key of the model.

DB::table('server_admins')->destroy($id);

Another method is to call the delete method on after retrieving the model.

$admin = DB::table('server_admins')::find($id);
$admin->delete();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.