Changing horses mid-race
I recently worked on a project where the requirements changed a few times. One change necessitated having to split the public facing website, and the admin panel and API across different IP addresses. The website was going to be managed on a SaaS service like SquareSpace, so that IP address was fixed and non-negotiable.
So the admin now had to go on a sub-domain. The admin project and API for mobile apps is built in Laravel and FilamentPHP. I use Forge for managing server environments. The project wasn’t yet in production so I could be fairly cavalier about downtime.
example.com example.com/admin
Here’s how it went.
Adding the sub-domain
I had access to the client’s domain record so I added a new A record for the sub-domain. Let’s call it admin. And I added the IP address that we’d already been using for the website.
Then I changed the IP address of the original A record, @, to point to the domain registrar’s parked IP.
Changes in Forge
Next I logged into Forge and changed the site address to admin.example.com
I also edited the .env file on production using Forge and changed the APP_URL key to “https://admin.example.com”
Filament AppProvider
Next go to app/Providers/Filament/AdminPanelProvider.php and make some changes.
I made 2 changes here. I set a domain variable and also changed the path of the panel as it felt unnecessary to have the /admin as we would soon be operating on a sub-domain.
First I checked which environment the app was running so I could set the appropriate domain.
public function panel(Panel $panel): Panel
{
if (config('app.env') === 'production') {
$domain = 'admin.example.com;
} else {
$domain = 'vp.test';
}
return $panel ….
Then I made changes to the $panel
return $panel
->default()
->id('admin')
->domain($domain)
->path('/')
->defaultThemeMode(ThemeMode::Light)
Note that the id of the panel is still admin even though I have changed the path to / instead of the original /admin
Make sure that when you push the new code that you bust all the caches for config and routes etc
Storage
You should now be able to log in at admin.example.com
Any uploads or files you need to load to display on pages will be unavailable, but if you SSH into the server you can quickly run
php artisan storage:link
to recreate the storage symlink.