Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function create(Request $request)
- {
- $categories = Category::whereNull('category_id')->with('childrenCategories')->get();
- return view('product.create', compact('categories' ));
- }
- public function store(Request $request)
- {
- // error_reporting(E_ALL);
- // ini_set("display_errors", 1);
- // $this->validate($request, [
- // 'title' => 'required',
- // 'slug' => 'required|unique:products',
- // 'text' => 'required',
- // 'path' => 'nullable|image',
- // ]);
- //dd('stop');
- $product = new Product();
- $product->title = $request->input('title');
- $product->slug = $request->input('slug');
- $product->text = $request->input('text');
- $product->keywords = $request->input('keywords');
- $product->description = $request->input('description');
- $product->published = $request->input('published');
- $product->category_id = $request->input('category_id');
- $product->price = $request->input('price');
- $product->authorized_price = $request->input('authorized_price');
- $product->short_description = $request->input('short_description');
- $path =public_path().'/uploads/product_images/';
- $file = $request->file('path');
- foreach ($file as $f) {
- $filename = Str::random(20) .'.' . $f->getClientOriginalExtension() ?: 'png';
- $img = ImageInt::make($f);
- $img->resize(500,500)->save($path . $filename);
- $image = new Image();
- $image->path = '/uploads/product_images/'.$filename;
- $image->title = $request->input('title');
- $image->product_id = $product->id;
- $image->save();
- }
- return redirect('/product/create')->with('info', 'Данные сохранены');
- }
Advertisement
Add Comment
Please, Sign In to add comment