Skip to content
Advertisement

Deleting data from database using Laravel 8

I’m stuck with an issue relating to deleting data from my database

The DELETE method is not supported for this route. Supported methods: GET, HEAD. –

My controller for deleting –

public function destroy($id) {

        $project = Projects::findOrFail($id);
        $project->delete();
        return redirect('/')->with('msg', 'Your project is now done');
   }

My form for deleting the data –

form action="/projects/{{ $project->id }}" method="POST">

            @csrf
            @method('DELETE')
            <button>Finish your project</button>
        </form>

My route –

Route::delete('/projects/{id}', [ProjectController::class, 'destroy']);

Migration –

public function up() {

        Schema::create('projects', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->string('type');
            $table->string('assignment');
            $table->string('name');
            $table->json('extra');
        });
    }

And lastly my models –

class Projects extends Model {

    use HasFactory;
    protected $casts = [
        'extra' => 'array'
    ];
}

Advertisement

Answer

I used php artisan cache:clear at some point when debugging, which enables and clears cache. So the changes in my web.php routes file were not being applied, as they were cached.

Ty for the help guys ! 🙂

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement