本文整理汇总了PHP中app\Product::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::save方法的具体用法?PHP Product::save怎么用?PHP Product::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store(Request $request)
{
$input = $request->all();
$product = new Product();
$product->name = $input['name'];
$product->description = $input['description'];
$product->sku = $input['sku'];
$product->price = $input['price'];
$product->special_price = $input['special_price'];
if ($input['category'] != null) {
$product->category = $input['category'];
}
$product->is_active = $input['is_active'];
$product->quanlity = $input['quanlity'];
$product->save();
if (!is_null($input['images'])) {
$path = "/catalog/img/product/" . $product->id . "/";
foreach ($request->images as $img) {
$img_product = new ProductImage();
$img_product->pro_id = $product->id;
$imgName = $img->getClientOriginalName();
$img_product->pro_id = $product->id;
$img_product->path = $path . $imgName;
$img->move(public_path($path), $imgName);
$img_product->save();
}
}
return redirect('admin/product');
}
示例2: add
public function add(Request $request)
{
$category = Category::all();
if ($request->isMethod('post')) {
$input = $request->all();
$fileName = null;
if (!empty($input['image_url'])) {
$file = $input['image_url'];
$extension = $file->getClientOriginalExtension();
$fileName = rand(11111, 99999) . '.' . $extension;
$file->move("admin/product", $fileName);
$destinationPath = "admin/product";
$fileThumb = "400x300_" . $fileName;
$fileThumbBig = "600x500_" . $fileName;
$img = Image::make("{$destinationPath}/{$fileName}")->resize(400, 300);
$img->save("{$destinationPath}/{$fileThumb}");
$imgBig = Image::make("{$destinationPath}/{$fileName}")->resize(600, 500);
$imgBig->save("{$destinationPath}/{$fileThumbBig}");
}
$product = new Product();
$product->price = $input['price'];
$product->code = $input['code'];
$product->categories_id = $input['category'];
$product->image_url = $fileName;
$product->slug = $this->slugify($input['title']);
$product->translateOrNew(LaravelLocalization::setLocale())->title = $input['title'];
$product->translateOrNew(LaravelLocalization::setLocale())->summary = $input['summary'];
$product->translateOrNew(LaravelLocalization::setLocale())->description = $input['description'];
$product->save();
return redirect(LaravelLocalization::setLocale() . DIRECTORY_SEPARATOR . 'admin-product');
}
return view('admin.products.add', compact('category'));
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
// Validation //
$validation = Validator::make($request->all(), ['caption' => 'required|regex:/^[A-Za-z ]+$/', 'description' => 'required', 'userfile' => 'required|image|mimes:jpeg,png|min:1|max:1000']);
// Check if it fails //
if ($validation->fails()) {
return redirect()->back()->withInput()->with('errors', $validation->errors());
}
// Process valid data & go to success page //
$product = new Product();
$category_id = DB::table('categories')->where('name', $request->input('category'))->value('id');
$file = $request->file('userfile');
$destination_path = 'uploads/';
$filename = date('s-i-H-d-m-y') . '.' . $file->getClientOriginalExtension();
$file->move($destination_path, $filename);
$file_path = $destination_path . $filename;
$imagine = new Imagine();
$mode = ImageInterface::THUMBNAIL_INSET;
$imagine->open($file_path)->thumbnail(new Box(250, 250), $mode)->save($file_path);
$product->file = $file_path;
$product->category_id = $category_id;
$product->caption = $request->input('caption');
$product->description = $request->input('description');
$product->price = $request->input('price');
//$product->available = $request->input('available');
$product->save();
return redirect('admin/products')->with('message', 'You just uploaded a product!');
}
示例4: store
public function store()
{
$data = Input::all();
try {
$p = new Product();
$p->name = Input::get('name');
$p->description = Input::get('description');
$p->price = Input::get('price');
$p->active = 1;
$p->manufacturer_id = Input::get('manufacturer');
$p->rating = Input::get('rating');
$p->stock = Input::get('stock');
$p->created_at = time();
$p->updated_at = time();
$p->slug = Str::slug($p->name);
$p->save();
$images = array_filter(explode('###', Input::get('images')));
foreach ($images as $image) {
$img = new ProductImgs();
$img->product_id = $p->id;
$img->url = $image;
$img->created_at = time();
$img->updated_at = time();
$img->save();
}
} catch (Exception $e) {
print_r($e->getMessage());
$this->code = 400;
}
Response::json([], $this->code);
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// Validation //
$validation = Validator::make($request->all(), ['name' => 'required|unique:category_subs|max:255', 'categories' => 'required', 'sub_categories' => 'required', 'description' => 'required', 'price' => 'required', 'weight' => 'required', 'keyword' => 'required']);
$cur_clean = preg_replace('/\\./', '', $request->input('price'));
$kg = preg_replace('/\\,/', '.', $request->input('weight'));
$gram = $kg * 1000;
// Check if it fails //
if ($validation->fails()) {
return redirect()->back()->withInput()->with('errors', $validation->errors());
}
if ($request->input('publish') == "") {
$publish = 0;
} else {
$publish = 1;
}
$author = Auth::user()->id;
$product = new Product();
$seo = $request->input('name');
$seotitle = SeoHelper::seotitle($seo);
// save product data into database //
$product->name = $request->input('name');
$product->name_seo = $seotitle;
$product->id_categories = $request->input('categories');
$product->id_category_subs = $request->input('sub_categories');
$product->id_user = $author;
$product->base_price = $cur_clean;
$product->base_weight = $gram;
$product->keyword = $request->input('keyword');
$product->description = $request->input('description');
$product->publish = $publish;
$product->save();
Alert::success('Success Create ' . $request->input('name') . ' !')->persistent("Close");
return redirect('dropmin/product/list')->with('message', 'You just create product!');
}
示例6: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$ratatouille = new App\Product();
$ratatouille->week_no = date('W');
$ratatouille->year = date('Y');
$ratatouille->name = 'Ratatouille';
$ratatouille->description = 'Ratatouille is een Frans gerecht van gestoofde groenten, dat vooral in de Provence veel wordt bereid.';
$ratatouille->city_id = 1;
$ratatouille->save();
$spaghetti = new App\Product();
$spaghetti->week_no = date('W');
$spaghetti->year = date('Y');
$spaghetti->name = 'Spaghetti';
$spaghetti->description = 'Lorem ipsum.';
$spaghetti->city_id = 1;
$spaghetti->save();
$visgerecht = new App\Product();
$visgerecht->week_no = date('W');
$visgerecht->year = date('Y');
$visgerecht->name = 'Visgerecht';
$visgerecht->description = 'Lorem ipsum.';
$visgerecht->city_id = 2;
$visgerecht->save();
$testgerecht = new App\Product();
$testgerecht->week_no = date('W');
$testgerecht->year = date('Y');
$testgerecht->name = 'Test gerecht';
$testgerecht->description = 'Lorem ipsum.';
$testgerecht->city_id = 2;
$testgerecht->save();
}
示例7: store
public function store(Request $request)
{
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array('name' => 'required', 'brand' => 'required', 'price' => 'required|numeric');
$messages = ['required' => 'The :attribute field is required.', 'numeric' => 'The :attribute field must be numeric.'];
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
return response()->json(['error' => ['status' => ['code' => 400, 'statusText' => 'Bad Request'], 'errors' => $validator->errors()->all(), 'message' => 'Invalid request body. Ensure all fields are specified and in JSON format.']]);
} else {
$product = new Product();
$product->name = Input::get('name');
$product->brand = Input::get('brand');
$product->price = Input::get('price');
$product->created_at = new DateTime();
$product->updated_at = new DateTime();
if (Input::get('description') != null) {
$product->description = Input::get('description');
} else {
$product->description = '<small>No Descriptions</small>';
}
if (Input::get('imageUrl') == null) {
$product->imageUrl = 'https://cdn.filestackcontent.com/CwyooxXdTcWtwufoKgOf';
} else {
$product->imageUrl = Input::get('imageUrl');
}
if ($product->save()) {
return response()->json(['success' => true, 'product' => $product]);
} else {
return response()->json(['error' => ['status' => ['code' => 500, 'statusText' => 'Internal Server Error'], 'message' => 'Failed to create new product.']]);
}
}
}
示例8: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
// 验证一下必填项
$this->validate($request, ['name' => 'required', 'productImg' => 'required', 'purchasePrice' => 'required', 'price' => 'required', 'wholesalePrice' => 'required', 'description' => 'required']);
$status = ['ok' => false, 'msg' => ''];
$imgPath = ImageUtil::saveImgFromRequest($request, 'productImg', 'img/wd/product/' . Input::get('category'));
if (!is_null($imgPath)) {
$product = new Product(['name' => Input::get('name'), 'subtitle' => Input::get('subtitle'), 'thumbnail' => $imgPath, 'category_id' => Input::get('category'), 'domestic_price' => Input::get('purchasePrice'), 'retail_price' => Input::get('price'), 'wholesale_price' => Input::get('wholesalePrice'), 'count' => Input::get('count'), 'description' => Input::get('description')]);
if (!$product->save()) {
$status['msg'] = trans('products.addNewProduct.errors.addError');
} else {
$status['ok'] = true;
// 这里需要记录一下进货记录
$log = new InventoryLog(['product_id' => $product->id, 'count' => Input::get('count'), 'price' => Input::get("purchasePrice"), 'type' => InventoryConfig::IN]);
$log->save();
}
} else {
$status['msg'] = trans('products.addNewProduct.errors.imgError');
}
if ($status['ok']) {
// return Redirect::back()->withMessage(['ok' => trans('products.addNewProduct.success.added')]);
// 暂时跳转到信息列表页面吧
// return redirect($request->getPathInfo());
// return redirect($request->getPathInfo() . '/create')->withMessages(
// ['ok' => trans('products.addNewProduct.success.added')]
// );
return redirect($request->getPathInfo())->withOk(trans('products.addNewProduct.success.added'));
} else {
return Redirect::back()->withInput()->withErrors($status['msg']);
}
}
示例9: loadFeed
/**
*
*/
public function loadFeed()
{
$xml = $this->reader->load($this->feedUrl);
$content = $xml->getContent();
$this->content = $xml->getContent();
foreach ($content as $product) {
$item = Product::where('externalUrl', '=', $product->productUrl)->first();
if (!$item) {
$item = new Product();
}
if (strlen($product->brand) > 1) {
$brand = Brand::where('name', '=', $product->brand)->first();
if (!$brand) {
$brand = new Brand();
$brand->name = $product->brand;
$brand->save();
}
if ($brand->id) {
$item->brand = $brand->id;
}
}
$item->name = $product->name;
$item->description = $product->description;
$item->price = $product->price;
$item->regularPrice = $product->regularPrice;
$item->shippingPrice = $product->shippingPrice;
$item->externalUrl = $product->productUrl;
$item->imageUrl = $product->graphicUrl;
$item->save();
}
}
示例10: import
public function import(Request $request)
{
$file = $request->file('arquivo');
$extension = $file->getClientOriginalExtension();
$import = new Import();
$import->user_id = 1;
$import->save();
Storage::disk('local')->put($import->id . '.' . $extension, File::get($file));
$handle = fopen($file, "r");
$firstTime = true;
while (($line = fgetcsv($handle, 1000, "\t")) !== false) {
if ($firstTime) {
$firstTime = false;
} else {
$produto = new Product();
$produto->import_id = $import->id;
$produto->purchaser_name = $line[0];
$produto->item_description = $line[1];
$produto->item_price = floatval($line[2]);
$produto->purchase_count = intval($line[3]);
$produto->merchant_address = $line[4];
$produto->merchant_name = $line[5];
$produto->save();
}
}
return view('index', ['imports' => Import::all()]);
}
示例11: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, ['product_title' => 'required']);
$product = new Product();
$product->is_published = $request->get('is_published') == 'on' ? 1 : 0;
$product->title = $request->get('product_title');
$product->description = $request->get('product_description');
$product->min_player = $request->get('product_input-players-min');
$product->max_player = $request->get('product_input-players-max');
$product->min_age = $request->get('product_input-age-min');
$product->cost_price = $request->get('product_costprice');
$product->sale_price = $request->get('product_saleprice');
$product->save();
if ($request->get('product_categories') != null) {
foreach ($request->get('product_categories') as $category_id) {
$product->categories()->attach($category_id);
}
}
$files = $request->file('product_images');
$count = 0;
foreach ($files as $file) {
if ($file == null) {
continue;
}
$product->addMedia($file)->usingFileName($product->id . "_" . $count . "." . $file->getClientOriginalExtension())->toCollection('images');
$count++;
}
Session::flash('flash_message', 'Product successfully added!');
return view('dashboard/create_product')->with('categories', Category::get())->with('product', new Product());
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ProductRequest $product_request)
{
$product = new Product();
$file_name = $product_request->file('illustration')->getClientOriginalName();
$product->product_name = $product_request->name;
$product->cate_id = $product_request->cate_id;
$product->brand_id = $product_request->brand_id;
$product->qty = $product_request->qty;
$product->price = $product_request->price;
$product->discount = $product_request->discount;
$product->description = $product_request->description;
$product->show = $product_request->show;
$product->feature = $product_request->feature;
$product->image_name = $file_name;
$product->slug = $product_request->slug;
$product_request->file('illustration')->move('upload', $file_name);
$product->save();
$product->size()->sync($product_request->size);
$product->color()->sync($product_request->color);
$product_id = $product->id;
if (Input::hasFile('images')) {
foreach (Input::file('images') as $file) {
$image = new Image();
if (isset($file)) {
$image->image_name = $file->getClientOriginalName();
$image->product_id = $product_id;
$file->move('upload/images', $file->getClientOriginalName());
$image->save();
}
}
}
return redirect()->route('admin.product.index')->with('alert-success', 'ADD complete');
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(ProductCreateRequest $request)
{
$product = new Product(array('name' => $request->get('name'), 'sku' => $request->get('sku'), 'price' => $request->get('price'), 'description' => $request->get('description'), 'is_downloadable' => $request->get('is_downloadable')));
$product->save();
// Process the uploaded image
$imageName = $product->sku . '.' . $request->file('image')->getClientOriginalExtension();
$request->file('image')->move(base_path() . '/public/imgs/products/', $imageName);
// Process the electronic download
if ($request->file('download')) {
$downloadName = $product->sku . '.' . $request->file('download')->getClientOriginalExtension();
$request->file('download')->move(storage_path() . '/downloads/', $downloadName);
$product->download = $downloadName;
$product->save();
}
return \Redirect::route('admin.products.edit', array($product->id))->with('message', 'The product has been added!');
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
try {
$user = JWTAuth::parseToken()->authenticate();
if ($user) {
$data = ['product_code' => $request->product_code];
$des = ['name' => $request->name, 'price' => $request->price];
$productCollection = Product::where($data)->get();
$product_des = new ProductDescription($des);
if ($productCollection->isEmpty()) {
//if collection not exist mean there is no entry of the productCode before
$product = new Product($data);
$product->save();
$product_des->product()->associate($product);
} else {
//since collection have some data get the product code from before n use it
$product = $productCollection[0];
//check if user already have the product with this product code
$array1 = $user->product_descriptions;
$array2 = $product->product_descriptions;
if (!$array1->intersect($array2)->isEmpty()) {
///if there is an instance of product description in it return error with msg in json
return response()->json(['message' => 'Error Product Existed']);
}
$product_des->product()->associate($product);
}
$user->product_descriptions()->save($product_des);
$message = ["message" => "Product Submitted"];
return json_encode($message);
}
} catch (JWTException $e) {
}
return response("Invalid User", 401);
}
示例15: scan
/**
* Register a product via barcode and uid (user id)
*
* @return \Illuminate\Http\JsonResponse
*/
public function scan()
{
header("Access-Control-Allow-Origin: *");
$response = new YYResponse(FALSE, 'Something went wrong.');
$validator = Validator::make(Request::all(), ['barcode' => 'required|integer', 'uid' => 'required|integer']);
if ($validator->fails()) {
$response->errors = $validator->errors();
return response()->json($response);
}
$product = Product::where(['barcode' => Request::get('barcode')])->get();
$product = empty($product[0]) ? NULL : $product[0];
if (empty($product)) {
$product = new Product();
$product->barcode = Request::get('barcode');
$product->uid = Request::get('uid');
$product->save();
}
if (!empty($product)) {
$response->state = TRUE;
$response->message = NULL;
$response->data = $product;
$response->data->reviews = Product::getReviewsById($product->id);
$response->data->rating = Product::getRatingById($product->id);
$response->data->rating->average = $response->data->rating->count > 0 ? $response->data->rating->total / $response->data->rating->count : 0;
$response->data->review = Product::getReviewsById($product->id, $product->uid);
}
return response()->json($response);
}