Here's my issue : I have a table in sqlserver database as follow :
Product (
id int identity,
reference varchar(12),
name varchar(40)
)
In a web page of a laravel web-app, I got a form with name only as field and a submit button. In DB side, I created a trigger (Instead of insert) that updates the reference of the row based on the generated id. Example :
RGX0000123
Where 123 is the generated ID and RGX is randomly generated.
The flow follows Post/Redirect/Get design pattern. After the submit, I want to redirect to a page where the reference is shown in the URL and not the ID.
In laravel's controller, I save my object with Eloquent and redirect to the next page :
$product->save();
return redirect()->route('next_page', ['reference' => $product->reference]);
My problem is that I can get the id after the save but not the reference. I don't know how Eloquent works but with Hibernate(JAVA) such thing can be resolved with a session.flush() to sync the object with data from the database.
Quick and dirty fix was using
$product= Product::find($product->id);
Is there a cleaner way to handle this ?