belongsTo('App\Models\GatewayType'); } /** * @param null $context * @return mixed */ public static function createNew($context = null) { $className = get_called_class(); $entity = new $className(); if ($context) { $user = $context instanceof User ? $context : $context->user; $account = $context->account; } elseif (Auth::check()) { $user = Auth::user(); $account = Auth::user()->account; } else { Utils::fatalError(); } $entity->user_id = $user->id; $entity->account_id = $account->id; // store references to the original user/account to prevent needing to reload them $entity->setRelation('user', $user); $entity->setRelation('account', $account); if (method_exists($className, 'trashed')){ $lastEntity = $className::whereAccountId($entity->account_id)->withTrashed(); } else { $lastEntity = $className::whereAccountId($entity->account_id); } return $entity; } public function setCreatedAtAttribute($value) { // to Disable created_at } }