当前位置: 首页>>代码示例>>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;未经允许,请勿转载。