當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。