Looking at https://laravel.com/docs/10.x/routing#route-group-subdomain-routing I try to make subdomains for my laravel 10 / livewire 3 app on my
home kubuntu 22.04
In routes/web.php I added :
Route::domain('{company}.'.config('app.url'))->group(function () {
Route::get('/', HomePage::Class);
Route::get('/news-details-page/{slug}', NewsDetailsPage::Class)->name('news.details');
Route::get('/news{news}', NewsListingPage::Class)->name('news.listing');
});
and in app/Livewire/HomePage.php :
class HomePage extends Component
{
public string $companySlug = '';
public $selectedCompany;
public function mount(?string $companySlug = '')
{
$this->companySlug = $companySlug;
$this->selectedCompany = Company::getBySlug($this->companySlug)->first();
if (empty($this->selectedCompany)) {
$this->selectedCompany = Company::getByActive(CompanyActiveEnum::ACTIVE)->first();
}
...
}
I run server with command :
php artisan serve
But url in browser
http://main-office.127.0.0.1:8000
where "main-office" is slug of one of companies.
does not work, browser use it for search.
In route aputputs I have :
GET|HEAD {company}.127.0.0.1:8000/ ................................................................................................................................................ generated::UVdHOKqavkOQwvfV › App\Livewire\HomePage
GET|HEAD {company}.127.0.0.1:8000/news-details-page/{slug} ................................................................................................................................ news.details › App\Livewire\NewsDetailsPage
GET|HEAD {company}.127.0.0.1:8000/news{news} .............................................................................................................................................. news.listing › App\Livewire\NewsListingPage
Which way is correct? Have I to add any subdomain/company in /etc/hosts of my OS ?
In .env I changed :
APP_URL=localhost
and cleared cache
In browser try to run url
http://main-office.localhost
Then apache default page is opened
On
http://main-office.localhost:8000/
My App is opened but shows
404 NOT FOUND
error
Which way is correct ?