Laravel 从哪里得到 references() 方法?

Where did Laravel get references() method?

我已经被困了一个小时了,因为我试图找出 Laravel 5.2 从哪里获得 references() 方法代码如下所示

Schema::create('articles', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('user_id');
        $table->string('title');
        $table->text('body');
        $table->text('excerpt')->nullable();
        $table->timestamps();
        $table->timestamp('published_at');

        $table->foreign('user_id')->references('id')->on('users');
});

我似乎无法在 \Illuminate\Database\Schema\Blueprint 或 Illuminate\Support\Fluent 中找到 references() 方法。

谁能指出上面代码中的 references() 方法在哪里可以找到?

任何帮助和提示都会很棒

看起来是 Fluent 通过 __call 魔术方法处理的。

Laravel API - Fluent @__call

任何不存在(或不可访问)的方法调用都将传递给 __call,后者会将方法命名的属性设置为您传递的值。

例子

$f = new \Illuminate\Support\Fluent;
$f->something('value')->willBeTrue();

dump($f);
//
Illuminate\Support\Fluent {
  #attributes: array:2 [
    "something" => "value"
    "willBeTrue" => true
  ]
}

当我打开蓝图时,我发现了与 lagbox 相同的东西 class 并且看到它正在使用 Fluent,它实现了 Arrayable 和 Jsonable 之间的几个契约,实际上任何不存在的方法都会被传递到 __call 方法,它将在属性数组中创建一个新元素,键作为方法名称:

$this->attributes[$method] = count($parameters) > 0 ? $parameters[0] : true;

但我仍然会扩展这个问题:在数据库记录上创建外键约束时,它真正在哪里使用 属性?我知道深入研究并没有多大用处,但我发现自己真的很好奇架构构建器在捕获这些方法之外是如何工作的。

另一个值得一提的是像 onDelete('cascade') 这样的触发器,通常在这种情况下使用。