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/" 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'
];
}
source https://stackoverflow.com/questions/68967368/deleting-data-from-database-using-laravel-8
Comments
Post a Comment