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 ?
UPDATED # 1:
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 ?
UPDATED # 2:
I added new hosting with /etc/apache2/sites-available/local-news-publishers.com.conf file :
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /_wwwroot/lar/NewsPublisher/public
ServerName local-news-publishers.com
ServerAlias local-news-publishers.com
<Directory /_wwwroot/lar/NewsPublisher/public>
AllowOverride All
Order Deny,Allow
Allow from all
Require all granted
</Directory>
Options FollowSymLinks
DirectoryIndex index.php
ErrorLog /_wwwroot/lar/NewsPublisher/storage/logs/error.log
CustomLog /_wwwroot/lar/NewsPublisher/storage/logs/access.log combined
</VirtualHost>
and added line in /etc/hosts :
127.0.0.1 localhost
127.0.1.1 master-at-home
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
...
127.0.0.7 local-quizzes.com
127.0.0.8 local-news-publishers.com
in .env of the app :
APP_URL=http://local-news-publishers.com
I restarted apache and clear cache of the app.
But running in my browser :
http://main-office.local-news-publishers.com
I got error in my browser :
This site can’t be reachedCheck if there is a typo in main-office.local-news-publishers.com.
DNS_PROBE_FINISHED_NXDOMAIN
But As I wrote above :
On
http://main-office.localhost:8000/
My app was opened but shows app error :
404 NOT FOUND
Which setting have I to use ?