Advertisement
1pppp

Untitled

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