Advertisement
1pppp

Untitled

Aug 6th, 2020
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. Почему картинка не сохраняется в другой таблице? У меня связь многие ко многим. Товар сохраняется , а картинки не сохраняется в базе. В папку на сайте тоже картинки не сохраняются
  2. Куда копать? Как найти ошибку? Мне не нужно готовое решение. Скажите пожалуйста как мне найти ошибку?
  3.  
  4. public function create(Request $request)
  5. {
  6. $categories = Category::whereNull('category_id')->with('childrenCategories')->get();
  7.  
  8. return view('product.create', compact('categories' ));
  9. }
  10.  
  11.  
  12. public function store(Request $request)
  13. {
  14. // dd('stop');
  15.  
  16. $this->validate($request, [
  17. 'title' => 'required',
  18. 'slug' => 'required|unique:products',
  19. 'text' => 'required',
  20. 'path' => 'nullable|image',
  21.  
  22. ]);
  23.  
  24. $product = new Product();
  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->product_id = $request->input('product_id');
  33. $product->price = $request->input('price');
  34. $product->authorized_price = $request->input('authorized_price');
  35. // $product->path = $request->input('path');
  36. $product->short_description = $request->input('short_description');
  37. $product->save();
  38. // dd('stop');
  39.  
  40.  
  41. $path =public_path().'uploads/product_images';
  42. $file = $request->file('file');
  43. // dd($path);
  44.  
  45. foreach ($file as $f) {
  46. $filename = str_random(20) .'.' . $f->getClientOriginalExtension() ?: 'png';
  47. $img = ImageInt::make($f);
  48. $img->resize(500,500)->save($path . $filename);
  49. Image::create(['title' => $request->title, 'path' => $filename]);
  50. }
  51.  
  52.  
  53.  
  54.  
  55. return redirect('/product/create')->with('info', 'Данные сохранены');
  56. }
  57.  
  58. <?php
  59.  
  60. namespace App;
  61.  
  62. use Illuminate\Database\Eloquent\Model;
  63.  
  64. class Product extends Model
  65. {
  66. public function category()
  67. {
  68. return $this->belongsTo(Category::class);
  69. }
  70.  
  71.  
  72. public function images()
  73. {
  74. return $this->hasMany(Image::class);
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement