当前位置: 首页>>代码示例>>PHP>>正文


PHP Eloquent::create方法代码示例

本文整理汇总了PHP中Eloquent::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Eloquent::create方法的具体用法?PHP Eloquent::create怎么用?PHP Eloquent::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Eloquent的用法示例。


在下文中一共展示了Eloquent::create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 public static function create(array $attributes)
 {
     if (!array_get($attributes, 'module')) {
         throw new Exception("Module name should be passed!");
     }
     if (!array_get($attributes, 'parent_id')) {
         throw new Exception("parent_id should be passed!");
     }
     $langs = ci()->translate->languages_admin();
     $count = 0;
     $count_success = 0;
     foreach ($langs as $lang_slug => $lang) {
         $keys = filter_by_key_suffix($attributes, '_' . $lang_slug, true);
         foreach ($keys as $key => $val) {
             ++$count;
             $input = array('key' => $key, 'val' => $val, 'lang' => $lang_slug);
             $input['uid'] = (int) array_get($attributes, 'uid');
             $input['module'] = $attributes['module'];
             $input['parent_id'] = $attributes['parent_id'];
             if ($obj = parent::create($input)) {
                 ++$count_success;
             }
         }
     }
     return $count === $count_success;
 }
开发者ID:huglester,项目名称:pyrocms-helpers,代码行数:26,代码来源:eloquenttranslatedmodel.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = \Input::all();
     $validation = \Validator::make($input, $this->getRules());
     if ($validation->passes()) {
         $record = $this->Model->create($input);
         return \Redirect::route($this->routeName . 'show', $record->getKey());
     }
     return \Redirect::route($this->routeName . 'create')->withInput()->withErrors($validation);
 }
开发者ID:robgordijn,项目名称:bamboo,代码行数:15,代码来源:BambooController.php

示例3: create

 /**
  * When creating a post, run the attributes through a validator first.
  * @param array $attributes
  * @return void
  */
 public static function create(array $attributes = array())
 {
     App::make('Components\\Posts\\Validation\\PostValidator')->validateForCreation($attributes);
     $extras = array();
     $extras['contact_page'] = isset($attributes['contact']);
     $extras['contact_coords'] = isset($attributes['contact_coords']) ? $attributes['contact_coords'] : '';
     $attributes['extras'] = json_encode($extras);
     $attributes['featured'] = isset($attributes['featured']) ? true : false;
     $attributes['created_by'] = current_user()->id;
     return parent::create($attributes);
 }
开发者ID:doptor,项目名称:doptor,代码行数:16,代码来源:Post.php

示例4: create

 public static function create(array $attributes)
 {
     if (static::$updateByDefault) {
         $model = new static($attributes);
         $existing = $model->findUnique();
         if ($existing) {
             $existing->fill($attributes);
             $existing->save();
             return $existing;
         }
     }
     return parent::create($attributes);
 }
开发者ID:philtweir,项目名称:glossia-scratch-test-site,代码行数:13,代码来源:UuidModel.php

示例5: create

 public static function create(array $attributes)
 {
     $success = false;
     if ($results = parent::create($attributes)) {
         $parent_id = $results->getAttribute('id');
         $uid = (int) $results->getAttribute('uid');
         $translated = filter_by_key_prefix($attributes, 'translated_', true);
         $translated['uid'] = $uid;
         $translated['module'] = strtolower(get_called_class());
         $translated['parent_id'] = $parent_id;
         // we create child translated
         $success = EloquentTranslatedModel::create($translated);
     }
     return $success ? $results : false;
 }
开发者ID:huglester,项目名称:pyrocms-helpers,代码行数:15,代码来源:eloquenttranslated.php

示例6: create

 public static function create(array $attributes = array())
 {
     // dd($attributes);
     static::isValid($attributes);
     if (isset($attributes['captcha'])) {
         // Do not save the value of captcha to database
         unset($attributes['captcha']);
     }
     unset($attributes['_token']);
     $entry['form_id'] = $attributes['form_id'];
     unset($attributes['form_id']);
     $form = BuiltForm::findOrFail($entry['form_id']);
     $module_builder = new Services\ModuleBuilder();
     $form_fields = $module_builder->getFormFields($form->data);
     $fields = array_combine($form_fields['fields'], $form_fields['field_names']);
     $entry['data'] = json_encode($attributes);
     $entry['fields'] = json_encode($fields);
     // dd($entry);
     return parent::create($entry);
 }
开发者ID:jrafaelca,项目名称:Doptor,代码行数:20,代码来源:FormEntry.php

示例7: create

 /**
  * When creating a post, run the attributes through a validator first.
  * @param array $attributes
  * @return void
  */
 public static function create(array $attributes = array())
 {
     App::make('Components\\Posts\\Validation\\CategoryValidator')->validateForCreation($attributes);
     $attributes['created_by'] = current_user()->id;
     return parent::create($attributes);
 }
开发者ID:doptor,项目名称:doptor,代码行数:11,代码来源:Category.php

示例8: create

 /**
  * When creating a theme, run the attributes through a validator first.
  * @param array $attributes
  * @return void
  */
 public static function create(array $attributes = array())
 {
     $attributes['created_by'] = current_user()->id;
     return parent::create($attributes);
 }
开发者ID:doptor,项目名称:doptor,代码行数:10,代码来源:ThemeSetting.php

示例9: create

 public static function create(array $data = [])
 {
     $fullEntity = get_called_class();
     $reflection = new \ReflectionClass($fullEntity);
     $entity = $reflection->getShortName();
     $modelConfig = AdminHelper::modelExists($entity);
     if (!$modelConfig) {
         throw new \Exception("Model config for entity " . $entity . " doesn't exist.");
     }
     if ($modelConfig->index == 'tree') {
         $depth = 0;
         $parentData = (new static())->getParentData();
         if ($parentData['parentObject']) {
             $depth = $parentData['parentObject']->depth + 1;
         }
         $maxPos = static::getMaxPos('position', $parentData);
         $data['depth'] = $depth;
         $data['position'] = $maxPos + 1;
         if ($parentData['parentIdProperty'] && $parentData['parentId']) {
             $data[$parentData['parentIdProperty']] = $parentData['parentId'];
         } else {
             if ($depth > 0) {
                 throw new \Exception('Tree structure view: $parentData["parentIdProperty"] OR $parentData["parentId"] is false!');
             }
         }
     } else {
         if ($modelConfig->position) {
             $maxPos = static::getMaxPos('position', false);
             $data['position'] = $maxPos + 1;
         }
     }
     return parent::create($data);
 }
开发者ID:gtcrais,项目名称:gtcms,代码行数:33,代码来源:BaseModel.php

示例10: create

 /**
  * Create a new item
  * @return Model
  */
 public function create()
 {
     $model = $this->model->create($this->getInput());
     return $model;
 }
开发者ID:sharenjoy,项目名称:cmsharenjoy,代码行数:9,代码来源:EloquentBaseRepository.php


注:本文中的Eloquent::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。