Laravel 6 onDelete->;(';设置null';)不工作

Laravel 6 onDelete->;(';设置null';)不工作,laravel,laravel-6,Laravel,Laravel 6,我的CRUD应用程序有一个奇怪的错误。onUpdate->('cascade')有效,但不适用于onDelete->('set null')。如果我在数据库中手动删除它,它会起作用,但在控制器中使用delete操作时不会起作用。请参阅下面我的迁移文件 class CreatePositionsTable扩展了迁移 { 公共职能 { Schema::create('positions',函数(Blueprint$表){ $table->bigIncrements('id'); $table->bi

我的CRUD应用程序有一个奇怪的错误。
onUpdate->('cascade')
有效,但不适用于
onDelete->('set null')
。如果我在数据库中手动删除它,它会起作用,但在控制器中使用delete操作时不会起作用。请参阅下面我的迁移文件

class CreatePositionsTable扩展了迁移
{
公共职能
{
Schema::create('positions',函数(Blueprint$表){
$table->bigIncrements('id');
$table->bigInteger('department_id')->unsigned()->nullable();
$table->foreign('department_id')->references('id')->on('departments'))
->onDelete('set null')->onUpdate('cascade');
$table->bigInteger('section_id')->unsigned()->nullable();
$table->foreign('section_id')->引用('id')->on('sections'))
->onDelete('set null')->onUpdate('cascade');
$table->string('position_name',100);
$table->string('n_level',10)->nullable();
$table->string('job_description')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
公共职能部门
{
Schema::dropIfExists('positions');
}
}
我的模型,如果这影响了什么

Positions.php

 <?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Iatstuti\Database\Support\CascadeSoftDeletes; //composer require iatstuti/laravel-cascade-soft-deletes

use App\SalaryMatrix;
use App\Employee;

class Position extends Model
{
    protected $fillable = ['department_id', 'section_id', 'position_name', 'n_level', 'job_description'];

    use SoftDeletes, CascadeSoftDeletes;
    protected $softCascade = ['deleted_at'];
    protected $cascadeDeletes = ['salaryMatrix', 'employee'];

    public function department () {
        return $this->belongsTo('App\Department');
    }

    public function section () {
        return $this->belongsTo('App\Section');
    }

    public function salaryMatrix() {
        return $this->hasOne('App\SalaryMatrix', 'position_id');
    }

    public function employee() {
        return $this->hasMany('App\Employee', 'position_id');
    }
}
 public function destroy($id) {
    $position = Position::findOrFail($id);
    $position->delete();
  }

注意:此项目仅部署在localhost中。

请说明如何删除行hello sir mrhn。我现在已经发布了我的控制器。但是当你删除职位时,级联设置null不应该工作,你能告诉我它如何与更新一起工作吗?级联用于更新部门id,你删除职位时不应该发生任何事情。更新时也没有意义,因为只有在Id更改时才会触发。你想在这里实现什么?当我更新一个记录时,新的值会更新为它的多个关系。这意味着onUpdate->('cascade')可以工作。我试图实现在删除部门或部门行时,表位置上的部门id或部门id应为空。当我在数据库中删除它(使用HeidiSQL)时,它会工作,但如果我使用控制器中指示的删除方法,它也会删除与被删除部门/部门有关系的职位。