app/Http/Controllers/ProductController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'product_name' => ['required', 'min:3', 'unique:products'],
            'category_id' => ['required'],
            'brand_id' => ['required'],
            'quantity' => ['required'],
            'weight' => ['required'],
            'thumbnail' => 'required | mimes:jpeg,jpg,png',
            'gallery' => ['mimes:jpeg,jpg,png,gif|required'],
            'gallery.*' => ['mimes:jpeg,jpg,png,gif|required'],
            'price' => ['required'],
            'offer_price' => ['required'],
            'summary' => ['required', 'max:500'],
            'description' => ['required'],
        ]);
        $product = new Product();
        $product->product_name = $request->product_name;
        $product->product_slug = $request->product_slug;
        $product->category_id = $request->category_id;
        $product->brand_id = $request->brand_id;
        $product->quantity = $request->quantity;
        $product->weight = $request->weight;
        $product->price = $request->price;
        $product->offer_price = $request->offer_price;
        $product->summary = $request->summary;
        $product->description = $request->description;
        if ($request->hasFile('thumbnail')) {
            $image = $request->file('thumbnail');
            $ext = Str::random(5) . '-' . $request->product_slug . '.' . $image->getClientOriginalExtension();
            Image::make($image)->save(public_path('frontend/img/product/' . $ext), 72);
            $product->thumbnail = $ext;
        }
        $product->save();
        if ($request->hasFile('image_name')) {
            $image = $request->file('image_name');
            foreach ($image as $key => $value) {
                $gallery = new Gallery();
                $extgallery = Str::random(10) . '-' . $request->product_slug . '.' . $value->getClientOriginalExtension();
                Image::make($value)->save(public_path('frontend/img/product/gallery/' . $extgallery), 72);
                $gallery->image_name = $extgallery;
                $gallery->product_id = $product->id;
                $gallery->save();
            }
        }
        return back()->with('success', 'Data Inserted Successfully');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'product_name' => [ 'required' , 'min:3' , 'unique:products' ] , 'category_id' => [ 'required' ] , 'brand_id' => [ 'required' ] , 'quantity' => [ 'required' ] , 'weight' => [ 'required' ] , 'thumbnail' => 'required | mimes:jpeg,jpg,png' , 'gallery' => [ 'mimes:jpeg,jpg,png,gif|required' ] , 'gallery.*' => [ 'mimes:jpeg,jpg,png,gif|required' ] , 'price' => [ 'required' ] , 'offer_price' => [ 'required' ] , 'summary' => [ 'required' , 'max:500' ] , 'description' => [ 'required' ] , ] ) ; $ product = new Product ( ) ; $ product -> product_name = $ request -> product_name ; $ product -> product_slug = $ request -> product_slug ; $ product -> category_id = $ request -> category_id ; $ product -> brand_id = $ request -> brand_id ; $ product -> quantity = $ request -> quantity ; $ product -> weight = $ request -> weight ; $ product -> price = $ request -> price ; $ product -> offer_price = $ request -> offer_price ; $ product -> summary = $ request -> summary ; $ product -> description = $ request -> description ; if ( $ request -> hasFile ( 'thumbnail' ) ) { $ image = $ request -> file ( 'thumbnail' ) ; $ ext = Str :: random ( 5 ) . '-' . $ request -> product_slug . '.' . $ image -> getClientOriginalExtension ( ) ; Image :: make ( $ image ) -> save ( public_path ( 'frontend/img/product/' . $ ext ) , 72 ) ; $ product -> thumbnail = $ ext ; } $ product -> save ( ) ; if ( $ request -> hasFile ( 'image_name' ) ) { $ image = $ request -> file ( 'image_name' ) ; foreach ( $ image as $ key => $ value ) { $ gallery = new Gallery ( ) ; $ extgallery = Str :: random ( 10 ) . '-' . $ request -> product_slug . '.' . $ value -> getClientOriginalExtension ( ) ; Image :: make ( $ value ) -> save ( public_path ( 'frontend/img/product/gallery/' . $ extgallery ) , 72 ) ; $ gallery -> image_name = $ extgallery ; $ gallery -> product_id = $ product -> id ; $ gallery -> save ( ) ; } } return back ( ) -> with ( 'success' , 'Data Inserted Successfully' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .