public static function create(array $attrubutes) { $user = new static(); if (!array_key_exists('nickname', $attrubutes)) { $user->nickname = static::generateNickname(); } foreach ($attrubutes as $key => $val) { $user->{$key} = $val; } $user->save(); \ProfileModel::firstOrCreate(['user_id' => $user->getKey()]); return $user; }
/** Returns the object if it is an instance of the Model class, and has * been instantiated; else null. So can set <tt>$var = Amodel::instantiated($var)</tt> * and it's either a real object or null. * @param static $var * @return static|null */ public static function instantiated($var = null) { if ($var instanceof static && $var->exists && $var->getKey()) { return $var; } return null; }