app/Http/Controllers/ProductsController.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)
    {
        $this->validate($request, [
            'name' => 'required|string',
            'description' => 'required|string',             
            'quantity' =>  'required|string',
            'price' => 'required|string',
            'farm_id'  => 'required|string',
            'category_id'  => 'required|string',
            'measurement_id' => 'required|string',          
          ]);
          $newProduct = products::create([
            'name'  => $request->name,
            'description'=> $request->description,
            'quantity' =>  $request->quantity,
            'price' =>  $request->price,
            'category_id'  => $request->category_id,
            'farm_id' =>  $request->farm_id,
            'measurement_units_id'  => $request->measurement_id,
            'isAvailable' => 1
          ]);
          if($newProduct->errors){
            return response()->json($newProduct, 424);
          }
          return response()->json($newProduct, 201);
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'name' => 'required|string' , 'description' => 'required|string' , 'quantity' => 'required|string' , 'price' => 'required|string' , 'farm_id' => 'required|string' , 'category_id' => 'required|string' , 'measurement_id' => 'required|string' , ] ) ; $ newProduct = products :: create ( [ 'name' => $ request -> name , 'description' => $ request -> description , 'quantity' => $ request -> quantity , 'price' => $ request -> price , 'category_id' => $ request -> category_id , 'farm_id' => $ request -> farm_id , 'measurement_units_id' => $ request -> measurement_id , 'isAvailable' => 1 ] ) ; if ( $ newProduct -> errors ) { return response ( ) -> json ( $ newProduct , 424 ) ; } return response ( ) -> json ( $ newProduct , 201 ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/// need to save image !!!!!!