Advertisement
1pppp

Untitled

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