1pppp

Untitled

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