为什么删除和销毁不删除模型的方法 - laravel

I'm trying to delete record from database I had write this code :

Route::get("/delete-student/{id}" , function ($id)
{
    $student = \App\Student\Student::find($id);
    $success = $student->delete();
    return ["success" => $success];
});

the result is ture but the record is still in database , I also tried this

$student = \App\Student\Student::destory($id);

but the record still not deleted

here is my student model

class Student extends Model
{
    protected $table = "student";
}

i had run to the same problem , the issue was because of the name of columns in my schema

laravel assume that each table has a primary key column named "id" , so if your primary key is not identical to "id" with lowercase you should override that by adding $primaryKey property to your model like this

protected $primaryKey = “YOUR_EXACT_KEY” ; //in my case was “Id”

I think you can try this :

Route::get("/delete-student/{id}" , function ($id)
{
    $student = \App\Student\Student::find($id);
    $success = $student->forceDelete();
    return ["success" => $success];
});

Hope this work for you !!!

Instead of find and delete you can directly delete the rows as follows

Route::get("/delete-student/{id}" , function ($id)
{
    $success = \App\Student\Student::where('id',$id)->delete();

    return ["success" => $success];
});

This will work in your case.