1pppp

Untitled

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