简体   繁体   中英

Laravel CRUD Delete function error

Here,what i want is when i press delete button necessary raw need to be deleted.that means relevant trainee_id and its details need to be deleted.

在此处输入图片说明 Here is the controller i`m using for that.

public function admin_destroy($trainee_id)
{
    registerdetails::where('trainee_id','=',$trainee_id)->first()->destroy(); 
}

Here is the route.

Route::get('Delete/{trainee_id?}', 'UserRegisterController@admin_destroy')
       ->where('trainee_id', '(.*)');;`

Here is the view button for delete.

<td>
    <a class="btn btn-danger" href="Delete/{{ $item->trainee_id }}">Delete</a>
</td>

Here is the URL um getting when i press the delete button.

http://127.0.0.1:8000/Delete/MOB/TR/1739

Finally this the error i`m getting.

在此处输入图片说明

Can anyone suggest me to fix this error.

public function admin_destroy($trainee_id)
    {
        registerdetails::destroy($trainee_id)->first(); 
    }

use this

destroy method expects a key, or array of keys. Like so:

registerdetails::destroy($trainee_id);

You can also do:

registerdetails::where('trainee_id','=',$trainee_id)->delete();

Check the docs: https://laravel.com/docs/5.4/eloquent#deleting-models

the destroy() function needs a parameter (either a single id or array of ids or ids seprated by comma) to be passed as

App\registerdetails::destroy(1);

App\registerdetails::destroy([1, 2, 3]);

App\registerdetails::destroy(1, 2, 3);

either pass the id to the destroy like this

registerdetails::destroy($trainee_id); 

or use delete() method to delete as

registerdetails::where('trainee_id','=',$trainee_id)->delete();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM