Ad

How To Use Url() To Get Domain Routes Laravel 5.2

- 1 answer

consider the following example:

Route::group(['domain' => 'something.example.local'], function() {
    Route::get('scripts', '[email protected]');
});

Now lets assume you are are on something.example.local/scripts and you hover over a link as such: <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ url(/scripts) }}">hello world</a> you will see something.example.local/scripts. great.

No go to example.local and do the same thing: example.local/scripts .... Thats wrong. It should say: something.example.local/scripts.

How do you use laravel helper methods to get the appropriate and complete url, domain and all?

Ad

Answer

I think you should name your route.

Here:

Route::group(['domain' => 'something.example.local'], function() {
    Route::get('scripts', ['as' => 'route.name', 'uses' => '[email protected]']);
});

And in your a tag:

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ route('route.name') }}">hello world</a>

Done!

Ad
source: stackoverflow.com
Ad