title: Laravel URL helper: How to generate a perfect URL with query parameters and hash
body: <p>Suppose the route is like this:</p>
  
  <pre><code>Route::get('messages/{messages}', ['as' =&gt; 'messages.show', 'uses' =&gt; 'MessagesController@show']);
  </code></pre>
  
  <p>So, when we will create an URL using URL helper of Laravel,</p>
  
  <pre><code>{{ route('messages.show', 12) }}
  </code></pre>
  
  <p>will display <code>example.com/messages/12</code>. </p>
  
  <p>This is correct. Let's have some hash in the URL.</p>
  
  <pre><code>{{ route('messages.show', [12, '#reply_23']) }}
  </code></pre>
  
  <p>This will display <code>example.com/messages/12#reply_23</code>. </p>
  
  <p>This looks good. Now let's add some query strings instead of the hash.</p>
  
  <pre><code>{{ route('messages.show', [12, 'ref=email']) }}
  </code></pre>
  
  <p>This will display <code>example.com/messages/12?ref=email</code>. This looks cool.</p>
  
  <p>Now add both query string and hash.</p>
  
  <pre><code>{{ route('messages.show', [12, 'ref=email', '#reply_23']) }}
  </code></pre>
  
  <p>Now this will display <code>example.com/messages/12?ref=email&amp;#reply_23</code>. This looks little ugly because of the <code>&amp;</code> in the URL. However it's not creating a lot of problem, I would like to get a clean URL like <code>example.com/messages/12?ref=email#reply_23</code>. Is there a way to get rid of the unnecessary <code>&amp;</code> in the URL?</p>
  
  <p><strong>Edit:</strong>
  There is a workaround, but I am looking for a solid answer.</p>
  
  <pre><code>&lt;a href="{{ route('messages.show', [12, 'ref=email']) }}#reply_23"&gt;Link to view on website&lt;/a&gt;
  </code></pre>