Francisunoxx Francisunoxx - 6 months ago 15
PHP Question

Is there a route for destroy method?

Can anyone tell me if there's a route for destroy method? I'm trying to delete my records in table but when I hit the Delete button is says my route is not define I think that's why my delete action won't work.

Route [result.destroyEmployee] not defined. (View: C:\Users\JohnFrancis\LaravelFrancis\resources\views\account\search.blade.php)


'uses' => '\App\Http\Controllers\AccountController@getEmployee',
'as' => '',

'uses' => '\App\Http\Controllers\AccountController@editEmployee',
'as' => 'account.edit',

I passed the
in the edit routes so it will identify who id is currently in action.


public function getEmployee()
$result = DB::table('users')->get();

return view ('')->with('result', $result);

public function editEmployee($id)
$result = User::find($id);

//key //value
return view ('account.edit')->with('result', $result);

public function destroyEmployee($id)
$result = User::destroy($id);

return redirect()->route('');


@foreach ($result as $row)
<tr class = "success">
<td>{{ $row->id }}</td>
<td>{{ $row->first_name }}</td>
<td>{{ $row->last_name }}</td>
<td>{{ $row->middle_name }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->username }}</td>
<a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a>

<a href = "{{ route ('result.destroyEmployee', $row->id) }}"><button type = "submit" class = "btn btn-danger">Delete</button></a>


<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit', $result->id) }}">

<div class = "form-group">

<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}">


<div class = "form-group">

<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}">


<div class = "form-group">

<button type = "submit" class = "btn btn-success">Save</button>


<input type = "hidden" name = "id" value = "{{ $result->id }}">
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">



Add this route in your routes.php. I don't encourage delete operation in a GET request, but since you have the operation defined on anchor tag, it will be a GET request.

    'uses' => 'AccountController@destroyEmployee',
    'as' => 'result.destroyEmployee',

You don't have this route defined and you are trying to hit it on clicking Archive button