phplaravellaravel-5illuminate-container

What happened to Laravel's Eloquent public static function "create" in Model.php?


In previous versions of Laravel 5.x (I'm not sure when it was changed) I was able to call static method create on any Eloquent Model class to insert records into a database.

For example:

EloquentUser::create([
    'name' => self::ADMIN_NAME,
    'email' => self::ADMIN_EMAIL,
    'password' => bcrypt(self::ADMIN_PASSWORD),
]);

That was calling public static function create in Model.php (vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php).

public static function create(array $attributes = [])
{
    $model = new static($attributes);

    $model->save();

    return $model;
}

In Laravel 5.5 I'm still able to call create however Model.php is totally rearranged and does not contain this method. What's more important, searching within whole vendor / Illuminate gives me nothing like that. Please explain, how it still works, what it calls behind the scenes.

enter image description here

Thanks.


Solution

  • Eloquent's _call and _callStatic are forwarding calls to an Eloquent Builder instance. The create method was moved out of the Model and into the Builder.

    Illuminate\Database\Eloquent\Model::__callStatic -> __call -> newQuery -> Illuminate\Database\Eloquent\Builder@create