how to pass auto generated input to an api function in laravel i have a web system whereby the input fields are autogenerated and saved in the database.i want to push the input data to an api function and have been able to push some of the inputs.i have which is autogenerated but am unable to push it.its the systemid.here is the code that generates it
$SystemID = new SystemID('product');
$product = new product();
$product->systemid = $SystemID;
$product->save();
i have tried this code in the api function of the controller but it shows an error systemid cannot be null
$productdetails=new Product;
$productdetails->systemid =$request->systemid;
how can i pass the autogenerated systemid to the controller in the api?
You are not saving anything by doing this: $SystemID = new SystemID('product'); so there is no system id generated..
@stephen waweru is this SystemID an eloquent model? And what is the product you are passing in the constructor?
$SystemID = new SystemID;
$SystemID->name = 'product';
$SystemID->save();
// now you can use the `$SystemID->id`.
@Nakov nop the systemid isnt a model the product is a table..the SYSTEMID here is autogenerated and saved in the product table in the systemid column
@stephen waweru show the SystemID class buddy.. the constructor should not return a value. So you are forgetting something there..
@Nakov yes i have found the systemID class here it is
@stephen waweru I wish I can ask where did you find this, and what are you working on.. but that will be waste of my time I think..
the $id that is generated is private to the SystemID class, so you cannot access it. At least I don't see a method on how you can access it.
There are just two methods that require some kind of $t_id which I have no clue what it is, but it also won't return an ID that you expect I guess.
Sorry, but I can't help with so many unknowns.
@Nakov the systemid is created and saved in the products table perfectly.i have tested that and its working
@stephen waweru so you are using this $request->systemid; in your "API Controller" but how are you sending it? Do you send it in the request body?
You are not showing any of your code.. just how you try to use it, which is hard to predict.
@Nakov i was asking how i can request the systemid that was autogenerated and saved at the products table
@stephen waweru for that you need to fetch the product by its id:
$productdetails= Product::find(1);
// here is your system id
dd($productdetails->systemid);
you cannot access a saved product with new Product that creates a NEW product..
@Nakov i have tried this but it doesnt work,its throwing an error in the log file at the endpoint api
Too few arguments to function App\Http\Controllers\APIController::push_data()
Please sign in or create an account to participate in this conversation.