title: How can I automatically add some query parameters to all links in Laravel Blade templates?
body: <p>I'm using Laravel 8.
  I display some links in Blade templates using the <code>route()</code> helper:</p>
  <pre class="lang-php prettyprint-override"><code>    &lt;a href=&quot;{{ route('foo', ['bar'=&gt;'baz']) }}&quot;&gt;Hello world&lt;/a&gt;
  </code></pre>
  <p>Which results in something like:</p>
  <pre class="lang-html prettyprint-override"><code>    &lt;a href=&quot;https://example.com/foo?bar=baz&quot;&gt;Hello world&lt;/a&gt;
  </code></pre>
  <p>However, I would like to have more query parameters added <em>automatically</em> to the url:</p>
  <pre class="lang-html prettyprint-override"><code>    &lt;a href=&quot;https://example.com/foo?bar=baz&amp;src=mailing&quot;&gt;Hello world&lt;/a&gt;
  </code></pre>
  <p>Idealy, I would like to activate this feature with a Blade directive</p>
  <pre class="lang-php prettyprint-override"><code>&lt;a href=&quot;{{ route('foo', ['bar'=&gt;'baz']) }}&quot;&gt;Hello world&lt;/a&gt;
  &lt;a href=&quot;{{ route('cool') }}&quot;&gt;Cool!&lt;/a&gt;
  &lt;a href=&quot;{{ route('icecream', ['flavour'=&gt;'strawberry']) }}&quot;&gt;Strawberry icecream&lt;/a&gt;
  
  &lt;hr&gt;
  
  @withqueryparams(['src'=&gt;'mailing'])
  {{-- same code here, but the result will differ --}}
  &lt;a href=&quot;{{ route('foo', ['bar'=&gt;'baz']) }}&quot;&gt;Hello world&lt;/a&gt;
  &lt;a href=&quot;{{ route('cool') }}&quot;&gt;Cool!&lt;/a&gt;
  &lt;a href=&quot;{{ route('icecream', ['flavour'=&gt;'strawberry']) }}&quot;&gt;Strawberry icecream&lt;/a&gt;
  @withendqueryparams
  </code></pre>
  <pre class="lang-html prettyprint-override"><code>&lt;a href=&quot;https://example.com/foo?bar=baz&quot;&gt;Hello world&lt;/a&gt;
  &lt;a href=&quot;https://example.com/cool&quot;&gt;Cool!&lt;/a&gt;
  &lt;a href=&quot;https://example.com/icecream/strawberry&quot;&gt;Strawberry icecream&lt;/a&gt;
  
  &lt;hr&gt;
      
  &lt;a href=&quot;https://example.com/foo?bar=baz&amp;src=mailing&quot;&gt;Hello world&lt;/a&gt;
  &lt;a href=&quot;https://example.com/cool?src=mailing&quot;&gt;Cool!&lt;/a&gt;
  &lt;a href=&quot;https://example.com/icecream/strawberry?src=mailing&quot;&gt;Strawberry icecream&lt;/a&gt;
  </code></pre>
  <p>I know how to manually add query parameters to a route.
  I know how to define a Blade directives.</p>
  <p>However, I don't know how to automatically add query parameters to parsed routes.</p>