title: PHP / Laravel : Retrieve new info of Model after save()
body: <p>Here's my issue : I have a table in sqlserver database as follow :</p>
  
  <pre><code>Product ( 
   id int identity,
   reference varchar(12),
   name varchar(40)
  )
  </code></pre>
  
  <p>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 :</p>
  
  <pre><code>RGX0000123
  </code></pre>
  
  <p>Where 123 is the generated ID and RGX is randomly generated.</p>
  
  <p>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. </p>
  
  <p>In laravel's controller, I save my object with Eloquent and redirect to the next page : </p>
  
  <pre><code>$product-&gt;save();
  return redirect()-&gt;route('next_page', ['reference' =&gt; $product-&gt;reference]);
  </code></pre>
  
  <p>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.</p>
  
  <p>Quick and dirty fix was using </p>
  
  <pre><code>$product= Product::find($product-&gt;id);
  </code></pre>
  
  <p>Is there a cleaner way to handle this ?</p>