Ad

Where Did Laravel Get References() Method?

I've been stucked for quite an hour now as I am trying to find out where did Laravel 5.2 get the references() method code is shown below

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');
});

I can't seem to find the references() method in either \Illuminate\Database\Schema\Blueprint or Illuminate\Support\Fluent.

can anyone point me to where is the references() method in the above code can be found?

any help and tips would be great

Ad

Answer

Looks like it is handled by Fluent through the __call magic method.

Laravel API - Fluent @__call

Any method call that doesn't exist (or is inaccessible) will get passed to __call which will set an attribute, named by the method, to the value you have passed.

Example

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

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