0

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
                                                       |
|
3
  • Route::post != axios.delete else Route::delete() === axios.delete Commented Dec 15, 2020 at 4:12
  • @KamleshPaul thanks should i write this in web api? Commented Dec 15, 2020 at 4:17
  • Yes Route::delete('delete/{id}','AdminController@destroy'); Commented Dec 15, 2020 at 4:20

1 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

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.