app/Http/Controllers/ProductController1.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)
    {
        $validator = Validator::make($request->all(), [
            'prod_name' => 'required',
            'prod_price' => 'required',
        ]);
        if($validator->fails()){
            return $this->sendError('Error validation', $validator->errors());       
        }
           $add =  Product::create([
                'prod_name'=>$request->prod_name,
                'prod_price'=>$request->prod_price,
            ]);
            return $this->sendResponse($add,'Add Product Successfully');
        }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'prod_name' => 'required' , 'prod_price' => 'required' , ] ) ; if ( $ validator -> fails ( ) ) { return $ this -> sendError ( 'Error validation' , $ validator -> errors ( ) ) ; } $ add = Product :: create ( [ 'prod_name' => $ request -> prod_name , 'prod_price' => $ request -> prod_price , ] ) ; return $ this -> sendResponse ( $ add , 'Add Product Successfully' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// dd($add);