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


PHP Category::validate方法代码示例

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


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

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $parent = !empty($request->input('parent_id')) ? Category::find($request->input('parent_id')) : null;
     $data = $request->only(['name', 'name_ru', 'parent_id']);
     $category = new Category($data);
     if (($messages = $category->validate()) === true) {
         Category::create($data, $parent);
         $response = array('result' => "{$request->input('name')} successfully added!");
         return \Response::json($response, 200);
     } else {
         return \Response::json($messages);
     }
 }
开发者ID:yurilabatsevich,项目名称:test.dev,代码行数:19,代码来源:CategoriesController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $category = new Category();
     $category->name = $request->input('name');
     $category->alias = $request->input('alias');
     $category->ordering = $request->input('ordering');
     if ($category->validate()) {
         $category->save();
         Session::flash('success', 'add success');
     } else {
         $errors = $category->errors;
         $messages = '';
         //dd($errors);
         foreach ($errors->all() as $error) {
             $messages .= $error . '<br>';
         }
         Session::flash('error', $messages);
     }
     return redirect('category/create')->withInput();
 }
开发者ID:pham-tam-mulodo,项目名称:laravel,代码行数:27,代码来源:CategoryController.php

示例3: create

 public function create()
 {
     $data = ['name' => Input::get('name'), 'description' => Input::get('description'), 'parent_id' => Input::get('parent_id'), 'id_path' => Input::get('id_path'), 'position' => Input::get('position')];
     if (isset($data) && is_array($data)) {
         $category = new Category();
         if ($category->validate($data)) {
             $category->name = $data['name'];
             $category->description = $data['description'];
             $category->parent_id = $data['parent_id'];
             $category->id_path = $data['id_path'];
             $category->position = $data['position'];
             $create = $category->save();
             if (!$create) {
                 return Redirect::route('categories')->with(['msg' => 'Failed to create!']);
             }
             return Redirect::route('categories')->with(['msg' => 'Successfully created!']);
         }
         return Redirect::route('categories')->with(['msg' => 'Failed to create!']);
     }
     return Redirect::route('categories')->with(['msg' => 'Failed to create!']);
 }
开发者ID:stijnwop,项目名称:breiShop,代码行数:21,代码来源:BackendCategoryController.php


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