create() public static method

Save a new model and return the instance.
public static create ( array $attributes = [] ) : static
$attributes array
return static
 public function store(CreateRoleRequest $request)
 {
     $data = $request->only(['name', 'description']);
     $this->roleModel->create($data);
     $this->setStatusMessage(trans('aliukevicius/laravelRbac::lang.role.messageCreated', ['name' => $data['name']]));
     return \Redirect::to($this->getRoleUrl('index'));
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function create(array $data)
 {
     $instance = $this->model->create($data);
     if (!$instance->getKey()) {
         throw new EntityCreateException('Failed to create entity');
     }
     return $instance;
 }
示例#3
0
 /**
  * Create a new model
  *
  * @param array  Data to create a new object
  * @return boolean
  */
 public function create(array $data)
 {
     $model = $this->model->create($data);
     if (!$model) {
         return false;
     }
     return $model;
 }
示例#4
0
 /**
  * Performs INSERT.
  *
  * @param $row
  */
 protected function insert($row)
 {
     if ($this->dryRun) {
         return;
     }
     $record = $this->model->create($row);
 }
示例#5
0
 public static function create(array $attributes = [])
 {
     if (array_key_exists('attachment', $attributes)) {
         $attributes['attachment'] = static::processAttachment($attributes['attachment']);
     }
     return parent::create($attributes);
 }
示例#6
0
 /**
  * Create a new model instance and store it in the database
  *
  * @param array $data
  * @return static
  */
 public function store(array $data)
 {
     // Remove non-fillable items from our data array
     foreach ($data as $key => $value) {
         if (!in_array($key, $this->model->getFillable())) {
             unset($data[$key]);
         }
     }
     // Do we need to create a reference id?
     $referenceColumn = $this->referenceIdColumnName();
     if ($this->model->isFillable($referenceColumn) && !isset($data[$referenceColumn])) {
         $data[$referenceColumn] = $this->generateReferenceId();
     }
     // Return the new model object
     return $this->model->create($data);
 }
示例#7
0
 /**
  * Create the model in the database.
  *
  * @param  array  $attributes
  * @return category
  */
 public static function create(array $attributes = [])
 {
     if (empty($attributes['alias'])) {
         $attributes['alias'] = Str::slug($attributes['name']) . '-' . Uuid::generate(4);
     }
     return parent::create($attributes)->fresh();
 }
 /**
  * Create a new model.
  *
  * @param  array $input
  * @throws Exception
  * @return mixed
  */
 public static function create(array $input)
 {
     static::beforeCreate($input);
     $return = parent::create($input);
     static::afterCreate($input, $return);
     return $return;
 }
示例#9
0
文件: Role.php 项目: emilmoe/guardian
 /**
  * Save a new model and return the instance.
  *
  * @param array $attributes
  * @return static
  */
 public static function create(array $attributes = [])
 {
     if (Guardian::hasClients()) {
         $attributes[Guardian::getClientColumn()] = Guardian::getClientId();
     }
     return parent::create($attributes);
 }
示例#10
0
 public static function create(array $attributes = [])
 {
     if (!array_key_exists('start_date', $attributes)) {
         throw new \RTMatt\MonthlyService\Exceptions\ServiceMonthNoDateException();
     }
     return parent::create($attributes);
 }
示例#11
0
 /**
  * @param array $data
  *
  * @return mixed
  */
 public function create(array $data)
 {
     $this->validate($data, ValidatorInterface::RULE_CREATE);
     $results = $this->model->create($data);
     $this->resetModel();
     return $this->parseResult($results);
 }
 /**
  * Create a new model instance and store it in the database
  *
  * @param array $data
  * @return static
  */
 public function store(array $data)
 {
     // Do we need to create a reference id?
     if ($this->model->isFillable('ref') && !isset($data['ref'])) {
         $data['ref'] = $this->generateReferenceId();
     }
     // Create the new model object
     $model = $this->model->create($data);
     // Do we need to set a hash?
     if ($this->model->isFillable('hash')) {
         $model->hash = \Hashids::encode($model->id);
         $model->save();
     }
     // Return the new model object
     return $model;
 }
示例#13
0
 public static function create(array $attributes = [])
 {
     if (config('global.managers.current.id')) {
         $data = array_merge($attributes, ['manager_id' => config('global.managers.current.id'), 'ip' => config('global.ip.current'), 'origin' => config('global.origin.current')]);
         parent::create($data);
     }
 }
示例#14
0
 /**
  * Create the model in the database.
  *
  * @param  array  $attributes
  * @return category
  */
 public static function create(array $attributes = [])
 {
     if (empty($attributes['alias'])) {
         $attributes['alias'] = Str::slug($attributes['title']);
     }
     $attributes['user_id'] = Auth::user()->id;
     return parent::create($attributes)->fresh();
 }
示例#15
0
 /**
  * Override of the create function, to incorporate a salt for password generation
  *
  * @param array attributes[];
  */
 public static function create(array $attributes = [])
 {
     if (self::isUnguarded()) {
         $attributes['password'] = password_hash($attributes['password'], PASSWORD_BCRYPT);
         $model = parent::create($attributes);
         return $model;
     }
 }
 /**
  * Create a new entity
  *
  * @param array $data
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(array $data)
 {
     $q = $this->model->create($data);
     if (!$q) {
         return $this->createError();
     }
     return $this->createSuccess();
 }
示例#17
0
 /**
  * Creates an item
  *
  * @param \Illuminate\Http\Request $data
  * @return \Illuminate\Http\JsonResponse
  */
 public function create(Request $data = null)
 {
     $data = $data ?: \Input::json();
     $json = $data->all();
     $json = $this->addAttribution($json);
     try {
         $this->model->validate($json);
         $item = $this->model->create($json);
         return $this->showByObject($item);
     } catch (ValidationException $e) {
         return $this->response->setStatusCode(422)->withError($e->errors()->all(), 'GEN-UNPROCESSABLE-ENTITY');
     } catch (MassAssignmentException $e) {
         return $this->response->setStatusCode(422)->withError("Cannot mass assign " . $e->getMessage(), 'GEN-UNPROCESSABLE-ENTITY');
     } catch (\Exception $e) {
         return $this->response->setStatusCode(422)->withError($e->getMessage(), 'GEN-UNPROCESSABLE-ENTITY');
     }
 }
示例#18
0
文件: Page.php 项目: bitsoflove/Page
 public static function create(array $data = [])
 {
     if (is_module_enabled('Site')) {
         $siteId = Site::id();
         $data['site_id'] = $siteId;
     }
     return parent::create($data);
 }
示例#19
0
 public static function create(array $data)
 {
     if (User::where('student_id', '=', $data['student_id'])->count() > 0) {
         return $data['student_id'] . " already exists";
     }
     parent::create($data);
     return $data['student_id'] . " added successfully";
 }
示例#20
0
 public static function create(array $options = [])
 {
     $res = Location::geocode($options['address'] . ' Tulsa, OK');
     $geo = $res->results[0]->geometry->location;
     $options['lat'] = $geo->lat;
     $options['lng'] = $geo->lng;
     return parent::create($options);
 }
示例#21
0
 public static function create(array $attributes = [])
 {
     $country = parent::create($attributes);
     /** @var $country Country */
     $army = Army::create(['size' => 2]);
     $country->army()->save($army);
     return $country;
 }
示例#22
0
 public static function create(array $attributes = array(), $confirmation = true)
 {
     $attributes["confirmation_code"] = \Uuid::generate()->string;
     $user = parent::create($attributes);
     if ($confirmation) {
         self::sendComfirmationMail($user);
     }
     return $user;
 }
示例#23
0
 public static function create(array $attributes = [])
 {
     $model = parent::create(array_except($attributes, 'instances'));
     if (array_key_exists('instances', $attributes) && !empty($attributes['instances'])) {
         $instances = collect($model->instances()->createMany($attributes['instances']));
         $model->setRelation('instances', $instances);
     }
     return $model;
 }
 /**
  * Record a notification for the user but make sure there are no duplicates first
  *
  * @param int    $userId
  * @param string $message
  * @param string $type
  * @param string $hash
  * @return Notification
  */
 public static function logNew($userId, $message, $type, $hash)
 {
     $existingNotifications = Notification::where('user_id', $userId)->where('hash', $hash)->first();
     if ($existingNotifications) {
         return $existingNotifications;
     }
     $newNotification = parent::create(['user_id' => $userId, 'message' => $message, 'type' => $type, 'hash' => $hash]);
     event(new NewMemberNotification($newNotification));
     return $newNotification;
 }
示例#25
0
 public static function create(array $attributes)
 {
     $length = 6;
     do {
         $attributes['slug'] = str_random($length);
         $exists = static::where('slug', '=', $attributes['slug'])->first();
         $length++;
     } while (!empty($exists));
     return parent::create($attributes);
 }
示例#26
0
 /**
  * Create Product
  * 
  * @param  array  $attributes        Attributes
  * @return PhpSoft\Illuminate\ShoppingCart\Model\Product
  */
 public static function create(array $attributes = [])
 {
     if (empty($attributes['alias'])) {
         $attributes['alias'] = Str::slug($attributes['title']) . '-' . Uuid::generate(4);
     }
     if (empty($attributes['galleries'])) {
         $attributes['galleries'] = [];
     }
     $attributes['galleries'] = json_encode($attributes['galleries']);
     return parent::create($attributes)->fresh();
 }
示例#27
0
 public static function create(array $attributes = [])
 {
     if (!array_key_exists('start_date', $attributes)) {
         throw new \RTMatt\MonthlyService\Exceptions\ServicePlanNoDateException();
     }
     $plan = parent::create($attributes);
     static::generateServiceMonths($plan);
     if (!(array_key_exists('skip_default_benefits', $attributes) && $attributes['skip_default_benefits'] === true)) {
         static::applyDefaultBenefits($plan);
     }
     return $plan;
 }
 /**
  * @param Entity $entity
  * @param array  $data
  * @return Entity
  */
 public function saveEntity(Entity $entity, $data = array())
 {
     if ($record = $this->model->find($entity->id())) {
         if (isset($data['updated_at'])) {
             $data['updated_at'] = date("Y-m-d H:i:s");
         }
         $record->update($data);
     } else {
         $record = $this->model->create($data);
         $entity->setId($record->id);
     }
     return $entity;
 }
 public static function create(array $attributes)
 {
     $purchase_id = array_get($attributes, 'purchase_id');
     $product_id = array_get($attributes, 'product_id');
     if (!$purchase_id or !$product_id) {
         return null;
     }
     $first = \App\Models\ProductInPurchaseModel::where('purchase_id', '=', $purchase_id)->where('product_id', '=', $product_id)->first();
     if ($first) {
         return null;
     }
     return parent::create($attributes);
 }
示例#30
0
 /**
  * @param array $attributes
  * @return void|static
  */
 public static function create(array $attributes = [])
 {
     // Add salt
     if (!array_key_exists('secret', $attributes) || $attributes['secret'] == '') {
         $secret = StringHelper::generateRandomString(20);
         $attributes['secret'] = $secret;
     }
     // Account status
     $attributes['account_status'] = self::ACCOUNT_ACTIVE;
     $model = parent::create($attributes);
     // Generate passkey
     UserPasskey::create(['user_id' => $model->id, 'passkey' => md5(StringHelper::generateRandomString() . time() . $model->secret)]);
     return $model;
 }