Reputation: 393
I have a problem with delete command. I receive this error in the console
DELETE http://localhost:8000/delete/37
405 (Method Not Allowed)
Am using laratrust to set the roles. Update and insert are working well the problem is delete.
in my AdminController
public function destroy($id)
{
$testUser = Auth::user();
if ($testUser->hasRole('superadministrator'))
{
$user=User::findOrFail($id);
$user ->delete();
return ['message'=>'Message Deleted'];
}
}
Vue Js table
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td><a href="#" @click="editModal(user)"><i class="fa fa-edit text- blue"></i></a>
/
<a href="#" @click="deleteUser(user.id)"><i class="fa fa-trash text-red"></i></a>
</td>
</tr>
</tbody>
Method
deleteUser(id){
axios.delete("delete/"+id);
//console.log('Your form id is'+id);
},
web route
Route::post('delete/{id}','AdminController@destroy');
When i try to view my routes using php artisan route:list i get this Php artisan route list
trust\Middleware\LaratrustRole:superadministrator |
| | POST | delete/{id} |
| App\Http\Controllers\AdminController@destroy | web
|
|
Upvotes: 0
Views: 146
Reputation: 12835
Define your route with delete method. It can remain within routes/web.php
if it is consumed by the frontend within the same project
Route::delete('delete/{id}','AdminController@destroy');
Upvotes: 1