1pppp

Untitled

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