Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stephen waweru's avatar

how to push a custom id generated by a helper class to an api post request

i have a web system whereby the productID input fields are generated using a helper function and saved in the products table.i want to push the productID to an api post request. here is the function that saves the productID

 $productID        = new productID('product');
 $product         = new product();
 $product->productid = $productID;
 $product->save();

here is my productID helper class

namespace App\Classes;
use Illuminate\Support\Facades\DB;

//class systemid
class SystemID
{
    private $type;
    private $id;
    private $invalid = false;
    private $allowed_type = array(
        'company'=>['company_seq','01'],
        'individual'=>['individual_seq','02'],
        'product'=>['product_seq','03'],
    );

    function __construct($type) {   
        if (!array_key_exists($type, $this->allowed_type)){
            $this->invalid =  true;

        } else {
            $data = $this->allowed_type[$type];
            $sequence = $data[0];
            $this->type = $data[1];
            $this->id = DB::select(
                "select nextval($sequence) as productID;")[0]->productID;
        }
    }
}
?>```
the class above generates the productID and saves it in the table on my website.what i want to achieve is push the generated productID to the an api endpoint.how can i achieve this fellow devs.
0 likes
1 reply

Please or to participate in this conversation.