當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::validate方法代碼示例

本文整理匯總了PHP中app\Product::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::validate方法的具體用法?PHP Product::validate怎麽用?PHP Product::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Product的用法示例。


在下文中一共展示了Product::validate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: create

 public function create()
 {
     $data = ['name' => Input::get('name'), 'title' => Input::get('title'), 'description' => Input::get('description'), 'category_id' => Input::get('category_id'), 'price' => Input::get('price'), 'VAT' => Input::get('VAT'), 'size' => Input::get('size'), 'color' => Input::get('color'), 'material' => Input::get('material'), 'details' => Input::get('details'), 'weight' => Input::get('weight'), 'stock' => Input::get('stock')];
     if (isset($data) && is_array($data)) {
         $product = new Product();
         if ($product->validate($data)) {
             $product->name = $data['name'];
             $product->title = $data['title'];
             $product->description = $data['description'];
             $product->category_id = $data['category_id'];
             $product->price = $data['price'];
             $product->VAT = $data['VAT'];
             $product->size = $data['size'];
             $product->color = $data['color'];
             $product->material = $data['material'];
             $product->details = $data['details'];
             $product->weight = $data['weight'];
             $product->stock = $data['stock'];
             if (Input::file('image')->isValid()) {
                 $fileName = rand(11111, 99999) . '.' . Input::file('image')->getClientOriginalExtension();
                 Input::file('image')->move('images/products/' . $product->id . '/', $fileName);
                 $product->image = $product->id . '/' . $fileName;
             } else {
                 return Redirect::route('products')->with(['msg' => 'Failed to create!']);
             }
             $create = $product->save();
             if (!$create) {
                 return Redirect::route('products')->with(['msg' => 'Failed to create!']);
             }
             return Redirect::route('products')->with(['msg' => 'Successfully created!']);
         }
         return Redirect::route('products')->with(['msg' => 'Failed to create!']);
     }
     return Redirect::route('products')->with(['msg' => 'Failed to create!']);
 }
開發者ID:stijnwop,項目名稱:breiShop,代碼行數:35,代碼來源:BackendProductController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $a = new Product();
     if (!$a->validate(Input::all())) {
         return redirect('product/create')->withErrors($a->errors())->withInput();
     }
     $a->fill(Input::all());
     $a->save();
     Flash::success('New product is created');
     return Redirect::to('product');
 }
開發者ID:e11en,項目名稱:allocatie,代碼行數:17,代碼來源:ProductController.php

示例3: saveProduct

 private function saveProduct(Request $request, Product $product)
 {
     $validator = Product::validate($request->all());
     if ($validator->fails()) {
         return redirect(route(Route::currentRouteName()))->withErrors($validator->errors());
     } else {
         if (!is_null($product->id)) {
             $product->update($request->all());
             Session::flash('success', "Le produit a bien été mis à jour.");
         } else {
             $product->fill($request->all());
             $product->save();
             Session::flash('success', "Le produit a bien été crée.");
         }
     }
     if ($param = Route::current()->getParameter('id')) {
         return redirect()->route(Route::currentRouteName(), $param);
     }
     return redirect()->route(Route::currentRouteName());
 }
開發者ID:polytechlyon-isi2,項目名稱:AgnamStore,代碼行數:20,代碼來源:ProductTrait.php


注:本文中的app\Product::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。