本文整理汇总了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!']);
}
示例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');
}
示例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());
}