本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例10: create
/**
* Create a new item
* @return Model
*/
public function create()
{
$model = $this->model->create($this->getInput());
return $model;
}