0

I using Laravel 5.4. Im trying to use dynamic domains like:

Route::group(array('domain' => '{domain}.com'), function (){//routes}

it works well if {domain} is something like example or test-domain but if i wanna try to generate free subdomains or use another free domains like sd1.example or example.free-domains , it returns fail: NotFoundHttpException in RouteCollection.php. I think it is because of point . . Laravel cant find .com maybe? Because if i use

Route::group(array('domain' => '{domain}.free-domain.com'), function (){//routes}

all is OK.

Is there any way to make Laravel look for .com from the end of string (address)? Or may be another workable solution? So, I just need to make it possible to use point . in {domain}

Thank You very much!

Khoniks
  • 29
  • 8
  • so what exact code break your flow? both your examples are working? which one does not? – Alex Jan 10 '18 at 19:47
  • Doesn’t work when {domain}.com and i try to go on example.myapp.com – Khoniks Jan 10 '18 at 20:14
  • it is still not clear. You've wrote that *it works well* when `'domain' => '{domain}.com'` in your post – Alex Jan 10 '18 at 20:36
  • When {domain}.myapp.com => example.myapp.com & when {domain}.com => example.com is ok (domain==example), but when {domain}.com => example.myapp.com - fail (domain == example.myapp). That’s a question. I need to put example.myapp into {domain} – Khoniks Jan 10 '18 at 20:47
  • did you check https://stackoverflow.com/questions/18603330/can-i-group-multiple-domains-in-a-routing-group-in-laravel ? – Alex Jan 10 '18 at 20:51
  • Not yet. didn’t see these solutions. I’ll try them. Thank you for links anyway :) – Khoniks Jan 10 '18 at 20:55

1 Answers1

0

Yep, i found good solution:

Route::pattern('tld', '(com|net|org|ru|local)');
Route::group(['domain' => '{domain}.{tld}'], function () {
//
}

and allow point in domain: in RouteServiceProvider.php:

public function boot()
    {
        app('router')->pattern('domain', '[a-z0-9.-]+');
        parent::boot();
    }

It works for me. Thanks!

Khoniks
  • 29
  • 8