1pppp

Untitled

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