本文整理汇总了PHP中app\models\Product::fill方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::fill方法的具体用法?PHP Product::fill怎么用?PHP Product::fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::fill方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store(EditProductRequest $request)
{
$product = new Product();
$product->fill($request->only($product->getFillable()));
$product->save();
return redirect()->route('product.index')->with('success_message', 'The product has been successfully saved.');
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateProductRequest $request, Product $product)
{
$data = $request->input();
$product->fill($data);
$product->save();
$this->savePhoto($product, $request);
$product->categories()->detach($product->categories()->lists('id')->toArray());
$product->categories()->attach($data['categories']);
return Redirect()->route('home');
}
示例3: store
/**
* Untuk menyimpan data product
*
* @param Request $request [description]
* @return [type] [description]
*/
public function store(Request $request, Supplierable $supplier)
{
$this->validate($request, ['code' => 'required', 'name' => 'required', 'description' => 'required', 'price' => 'required', 'category_id' => 'required']);
$data = $request->only('code', 'name', 'description', 'price', 'category_id');
if (is_string($request->get('tags'))) {
$tags = explode(',', $request->get('tags'));
} else {
$tags = $request->get('tags', []);
}
$product = new Product();
$product->fill($data);
$product->supplier()->associate($supplier);
$product->save();
$this->productRepository->saveTags($product, $tags);
if ($product) {
return ['status' => 'success', 'message' => 'Product has successfully added.', 'product' => $product];
} else {
return ['status' => 'failed', 'message' => 'Product has failed to be added.'];
}
}
示例4: store
/**
* Store a newly created resource in storage.
* @return Response
*/
public function store()
{
$validator = Validator::make(Input::all(), Product::$product_rules);
if ($validator->passes()) {
$user = Auth::user();
$file_rename = $this->renameImage();
if (Request::file('image')->move(public_path() . '/uploads', $file_rename)) {
$product_data = new Product();
$product_data->fill(Input::all());
$product_data['image'] = $file_rename;
if ($user->product()->save($product_data)) {
Session::flash('message.success', 'Item added successfully.');
return Redirect::to("home");
} else {
Session::flash('message.arrayErrors', $validator->messages()->all());
return Redirect::to('add-product')->withInput(Input::all());
}
}
} else {
Session::flash('message.arrayErrors', $validator->messages()->all());
return Redirect::to('add-product')->withInput(Input::all());
}
}
示例5: update
/**
* Update the specified product
*
* @param ProductRequest $request
* @param Product $product
* @return Response
*/
public function update(EditProductRequest $request, Product $product)
{
$input = $request->except('image');
$image = $request->file('image');
if (!isset($input['active'])) {
$input['active'] = false;
}
if (!isset($input['new'])) {
$input['new'] = false;
}
if ($image != null) {
// Picture name will be same as SKU
$name = $input['sku'];
// Extenstion of original picture
$extension = '.' . $image->getClientOriginalExtension();
// Set paths for full image and thumbnail
$imagePath = 'img/' . $name . $extension;
$thumbnailPath = 'img/thumbs/' . $name . $extension;
// Save original picture
\Image::make($image->getRealPath())->save(public_path($imagePath));
// Save resized thumbnail
\Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
})->save(public_path($thumbnailPath));
// Create Product model and save pictures
$product->fill($input);
$product->image = $imagePath;
$product->image_thumb = $thumbnailPath;
$product->save();
return redirect(route('AdminProductShow', $product->slug));
}
$product->fill($input);
$product->save();
return redirect(route('AdminProductShow', $product->slug));
}