1pppp

Untitled

Aug 5th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. public function store(Request $request)
  3. {
  4. // dd('stop');
  5.  
  6. $this->validate($request, [
  7. 'title' => 'required',
  8. 'slug' => 'required|unique:products',
  9. 'text' => 'required',
  10. 'path' => 'nullable|image',
  11.  
  12. ]);
  13.  
  14. $product = new Product();
  15. $product->title = $request->input('title');
  16. $product->slug = $request->input('slug');
  17. $product->text = $request->input('text');
  18. $product->keywords = $request->input('keywords');
  19. $product->description = $request->input('description');
  20. $product->published = $request->input('published');
  21. $product->category_id = $request->input('category_id');
  22. $product->product_id = $request->input('product_id');
  23. $product->price = $request->input('price');
  24. $product->authorized_price = $request->input('authorized_price');
  25. // $product->path = $request->input('path');
  26. $product->short_description = $request->input('short_description');
  27. $product->save();
  28. // dd('stop');
  29.  
  30.  
  31. $path =public_path().'uploads/product_images';
  32. $file = $request->file('file');
  33. // dd($path);
  34.  
  35. foreach ($file as $f) {
  36. $filename = str_random(20) .'.' . $f->getClientOriginalExtension() ?: 'png';
  37. $img = ImageInt::make($f);
  38. $img->resize(500,500)->save($path . $filename);
  39. Image::create(['title' => $request->title, 'path' => $filename]);
  40. }
  41.  
  42.  
  43.  
  44.  
  45. return redirect('/product/create')->with('info', 'Данные сохранены');
  46. }
Advertisement
Add Comment
Please, Sign In to add comment