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,$id)
    {
        $data=request()->validate([
            'product_name'=>'required',
            'product_short_description'=>'required',
            'product_code'=>'required',
            'product_description'=>'required',
            'product_features'=>'required',
            'product_category'=>'required',
            'tags'=>'required',
            'product_image'=>'required',
        ]);
        $imagePath = request('product_image')->store('ProductImages', 'public');
        $image = Image::make("storage/{$imagePath}")->fit(520, 600);
        $product=Product::create([
            'product_name'=>$data['product_name'],
            'product_short_description'=>$data['product_short_description'],
            'product_code'=>$data['product_code'],
            'product_description'=>$data['product_description'],
            'product_features'=>$data['product_features'],
            'product_category'=>$data['product_category'],
            'tags'=>$data['tags'],
            'product_image'=>$imagePath,
            'category_id'=>$id
        ]);
        return redirect('/products');
    }
public function store ( Request $ request , $ id ) { $ data = request ( ) -> validate ( [ 'product_name' => 'required' , 'product_short_description' => 'required' , 'product_code' => 'required' , 'product_description' => 'required' , 'product_features' => 'required' , 'product_category' => 'required' , 'tags' => 'required' , 'product_image' => 'required' , ] ) ; $ imagePath = request ( 'product_image' ) -> store ( 'ProductImages' , 'public' ) ; $ image = Image :: make ( " storage/ { $ imagePath } " ) -> fit ( 520 , 600 ) ; $ product = Product :: create ( [ 'product_name' => $ data [ 'product_name' ] , 'product_short_description' => $ data [ 'product_short_description' ] , 'product_code' => $ data [ 'product_code' ] , 'product_description' => $ data [ 'product_description' ] , 'product_features' => $ data [ 'product_features' ] , 'product_category' => $ data [ 'product_category' ] , 'tags' => $ data [ 'tags' ] , 'product_image' => $ imagePath , 'category_id' => $ id ] ) ; return redirect ( '/products' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .