本文整理汇总了PHP中Category::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::create方法的具体用法?PHP Category::create怎么用?PHP Category::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$input = Input::all();
$validation = Validator::make($input, Category::$rules);
if ($validation->passes()) {
$this->category->create($input);
return Redirect::to('admin?section=categories')->with(array('note' => Lang::get('lang.new_category_success'), 'note_type' => 'success'));
}
return Redirect::to('admin?section=categories')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$val = $this->categoryRepository->getCreateForm();
if (!$val->isValid()) {
return Redirect::back()->withInput()->withErrors($val->getErrors());
}
if (!($record = $this->categoryRepository->create($val->getInputData()))) {
return Redirect::back()->with('errors', $this->categoryRepository->errors())->withInput();
}
return Redirect::action('AdminCategoriesController@index')->with('success', 'Category Created');
}
示例3: createHandle
public function createHandle()
{
$path = DirectoryHelpers::seoString(e(Input::get('path')));
$nice_input_names = ['is_root' => trans('directory.is_root'), 'name' => trans('directory.name'), 'path' => trans('directory.path'), 'description' => trans('directory.description'), 'keywords' => trans('directory.keywords')];
$rules = ['is_root' => 'required', 'name' => 'required|between:2,50|unique:categories', 'path' => 'required|between:2,50|unique:categories', 'description' => 'between:5,1000', 'keywords' => 'between:5,255'];
$is_root = Input::get('is_root');
if ('no' == $is_root) {
$nice_input_names['parent_id'] = trans('directory.parent');
$rules['parent_id'] = 'not_in:0';
}
$validator = Validator::make(Input::all(), $rules, [], $nice_input_names);
if ($validator->fails()) {
return Redirect::route('category.create')->withErrors($validator)->withInput();
}
try {
if ('yes' == $is_root) {
$status = Acl::isSuperAdmin() ? 1 : 0;
$node = Category::create(['status' => $status, 'name' => e(Input::get('name')), 'slug' => $path, 'path' => $path, 'description' => e(Input::get('description')), 'keywords' => e(Input::get('keywords'))])->makeRoot();
}
if ('no' == $is_root) {
$parent = Category::find(e(Input::get('parent_id')));
$node = Category::create(['status' => $status, 'name' => e(Input::get('name')), 'slug' => $path, 'path' => $path, 'description' => e(Input::get('description')), 'keywords' => e(Input::get('keywords'))])->makeChildOf($parent);
}
Acl::addAdmin($node);
return Redirect::route('category.create')->with('success', Lang::get('directory.category_added', ['name' => Input::get('name')]));
} catch (Exception $ex) {
return Redirect::route('category.create')->withErrors($ex->getMessage())->withInput();
}
}
示例4: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Category::create([]);
}
}
示例5: run
public function run()
{
DB::table('categorys')->delete();
Category::create(array('name' => 'Feeling'));
Category::create(array('name' => 'Phycial'));
Category::create(array('name' => 'Logical'));
}
示例6: run
public function run()
{
Category::create(array('name' => 'Movies'));
Category::create(array('name' => 'Books'));
Category::create(array('name' => 'Music'));
Category::create(array('name' => 'Episodes'));
}
示例7: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Category::create(['name' => $faker->word, 'subscription_price' => $faker->sentence, 'test_price' => $faker->randomNumber, 'words' => $faker->randomNumber]);
}
}
示例8: run
public function run()
{
DB::table('categories')->delete();
Category::create(array('id' => 1, 'name' => 'Web Development'));
Category::create(array('id' => 2, 'name' => 'Web Design'));
Category::create(array('id' => 3, 'name' => 'Testing'));
}
示例9: create
function create($parent_id = FALSE)
{
//load block submit helper and append in the head
$this->template->append_metadata(block_submit_button());
//get the parent id
$parent_id = $this->uri->segment(4) ? $this->uri->segment(4) : $this->input->post('parent_id', TRUE);
//Filter & Sanitize $id
$parent_id = $parent_id != 0 ? filter_var($parent_id, FILTER_VALIDATE_INT) : NULL;
//Rules for validation
$this->_set_rules();
//create control variables
$this->template->set('title', lang('web_category_create'));
$this->template->set('updType', 'create');
$this->template->set('parent_id', $parent_id);
//validate the fields of form
if ($this->form_validation->run() == FALSE) {
//load the view and the layout
$this->template->build('categories/create');
} else {
// build array for the model
$form_data = array('name' => set_value('name'), 'category_id' => $parent_id);
$category = Category::create($form_data);
// run insert model to write data to db
if ($category->is_valid()) {
$this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_create_success')));
redirect('admin/categories/' . $parent_id);
}
if ($category->is_invalid()) {
//$this->session->set_flashdata('message', array( 'type' => 'error', 'text' => lang('web_create_failed') ));
$this->session->set_flashdata('message', array('type' => 'error', 'text' => $category->errors->full_messages()));
redirect('admin/categories/' . $parent_id);
}
}
}
示例10: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 3) as $index) {
Category::create(['name' => $faker->sentence(1), 'href' => '#']);
}
}
示例11: addGarmentCategory
public function addGarmentCategory()
{
$garms = Category::get();
$isAdded = FALSE;
$validInput = TRUE;
$regex = "/^[a-zA-Z\\'\\-]+( [a-zA-Z\\'\\-]+)*\$/";
$regexDesc = "/^[a-zA-Z0-9\\'\\-\\.\\,]+( [a-zA-Z0-9\\,\\'\\-\\.]+)*\$/";
if (!trim(Input::get('addGarmentName')) == '' || !trim(Input::get('addGarmentDesc')) == '') {
$validInput = TRUE;
if (preg_match($regex, Input::get('addGarmentName')) && preg_match($regexDesc, Input::get('addGarmentDesc'))) {
$validInput = TRUE;
} else {
$validInput = FALSE;
}
} else {
$validInput = FALSE;
}
foreach ($garms as $garm) {
if (strcasecmp($garm->strGarmentCategoryName, trim(Input::get('addGarmentName'))) == 0) {
$isAdded = TRUE;
}
}
if ($validInput) {
if (!$isAdded) {
$garment = Category::create(array('strGarmentCategoryID' => Input::get('addGarmentID'), 'strGarmentCategoryName' => trim(Input::get('addGarmentName')), 'strGarmentCategoryDesc' => trim(Input::get('addGarmentDesc')), 'boolIsActive' => 1));
$garment->save();
return Redirect::to('/maintenance/garments?success=true');
} else {
return Redirect::to('/maintenance/garments?success=duplicate');
}
} else {
return Redirect::to('/maintenance/garments?input=invalid');
}
}
示例12: store
/**
* Store a newly created category in storage.
*
* @return Response
*/
public function store()
{
$categoryValidator = Validator::make($data = Input::all(), Category::$rules);
if ($categoryValidator->fails()) {
return Redirect::back()->withErrors($categoryValidator)->withInput();
}
/* Category */
if (Input::has('createCategory')) {
Category::create($data);
$message = "登録しました。";
}
if (Input::has('deleteCategory')) {
$c = Category::where('Bumon', Input::get('Bumon'))->first();
Category::destroy($c->id);
$message = "削除しました。";
if (Input::has('selectedCategory')) {
Input::replace(array('selectedCategory', ''));
}
}
if (Input::has('updateCategory')) {
$err = array('required' => '新しい部門名を入力してください。');
$categoryValidator = Validator::make($data = Input::all(), Category::$update_rules, $err);
if ($categoryValidator->fails()) {
return Redirect::back()->withErrors($categoryValidator)->withInput();
}
$c = Category::where('Bumon', Input::get('Bumon'))->first();
Category::destroy($c->id);
$data['Bumon'] = $data['new_categoryName'];
Category::create($data);
$message = "更新しました。";
}
return Redirect::route('employees.index')->with('message', $message);
}
示例13: seedCategory
/**
* 填充分类数据
* @return void
*/
private function seedCategory()
{
foreach (array('PHP-PSR 代码标准', '新分类二', '新分类三', '新分类四', '新分类五') as $key => $value) {
Category::create(array('name' => $value, 'sort_order' => $key + 1));
}
$this->command->info('测试分类数据填充完毕');
}
示例14: run
public function run()
{
DB::table('users')->delete();
Category::create(['name' => 'Electronics']);
Category::create(['name' => 'Sports']);
Category::create(['name' => 'Furnitures']);
}
示例15: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Category::create(['title' => $faker->sentence()]);
}
}