app/Http/Controllers/api/ProductController.php
/**
     * Create product from request
     *
     * @param Request $request
     * @return json
     */
Create product from request
@param Request $request
@return json
Create product from request @param Request $request @return json
public function CreateProduct(Request $request){
        $validator = Validator::make($request->all(), [
            'title' => 'required|max:255',
            'description' => 'required',
            'price' => 'required|max:8',
            'image' => 'required|image',
        ]);
        if ($validator->fails()) {
            return response()->json([
                'type' => 'error',
                'message' => $validator->errors()
            ]);
        }
        $product = ProductModel::create($request->except(['image']));
        if($product){
            $imagePath = $request->file('image')->store('product-image','public');
            $product->image = $imagePath;
            $product->update();
        }
        return response()->json([
            'type' => 'success' , 
            'message' => ["Product Created"],
            'product' => $product
        ]);
    }
public function CreateProduct ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'title' => 'required|max:255' , 'description' => 'required' , 'price' => 'required|max:8' , 'image' => 'required|image' , ] ) ; if ( $ validator -> fails ( ) ) { return response ( ) -> json ( [ 'type' => 'error' , 'message' => $ validator -> errors ( ) ] ) ; } $ product = ProductModel :: create ( $ request -> except ( [ 'image' ] ) ) ; if ( $ product ) { $ imagePath = $ request -> file ( 'image' ) -> store ( 'product-image' , 'public' ) ; $ product -> image = $ imagePath ; $ product -> update ( ) ; } return response ( ) -> json ( [ 'type' => 'success' , 'message' => [ " Product Created " ] , 'product' => $ product ] ) ; }
Create product from request
 @param Request $request
 @return json
Create product from request @param Request $request @return json