0

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.

enter image description here 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.

enter image description here

Can anyone suggest me to fix this error.

Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45
Dasun
  • 602
  • 1
  • 11
  • 34
  • You are sending 3 parameters to url, it should be only one as you mentioned in route `http://127.0.0.1:8000/Delete/MOB/TR/1739` – Pankaj Makwana Jun 20 '17 at 07:32
  • What is line 196 of UserRegisterController? Also, your IDs have forward slashes in them which is going to be problematic in the URL, you'll need to handle them properly. – Dan Walker Jun 20 '17 at 07:33
  • You have to send three params to url Or change `href="Delete/{{ $item->trainee_id }}"` to `href="Delete/MOB/TR/{{ $item->trainee_id }}"` in `a` tag! – Hiren Gohel Jun 20 '17 at 07:35
  • @PankajMakwana, it looks like MOB/TR/1739 altogether is a single value which is the trainee_id he is trying – manian Jun 20 '17 at 07:36
  • You can try replacing `/` with another character in `MOB/TR/1739` and again replace another character with `/` on controller SO string should be `MOB##TR##1739` and then replace `##` with `/` – Pankaj Makwana Jun 20 '17 at 07:45

3 Answers3

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

use this

Exprator
  • 26,992
  • 6
  • 47
  • 59
1

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

HTMHell
  • 5,761
  • 5
  • 37
  • 79
1

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();
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70