When managing multiple client projects that share a common Laravel admin panel, keeping all projects synchronized while allowing for individual client customizations can be challenging. This guide explains how to set up a Laravel Admin Panel as a Git submodule and manage updates efficiently across multiple client projects.
1. Initial Commit for the Admin Panel
First, create a dedicated repository for the admin panel, which will act as the centralized version for all client projects.
Steps to Set Up the Admin Panel Repository
-
Create a new Laravel project:
composer create-project laravel/laravel admin-panel
-
Initialize a Git repository and commit the initial files:
cd admin-panel git init git add . git commit -m "Initial commit for Admin Panel" git branch -M main git remote add origin https://github.com/your-org/admin-panel.git git push -u origin main
Now, the admin panel is ready to be integrated into client projects.
2. Initial Commit for a Client Project
Each client project is a separate Laravel application that will include the admin panel as a submodule.
Steps to Set Up a Client Project
-
Create a new Laravel project for a client:
composer create-project laravel/laravel client-project-1
-
Initialize Git and push it to a remote repository:
cd client-project-1 git init git add . git commit -m "Initial commit for Client Project 1" git branch -M main git remote add origin https://github.com/your-org/client-project-1.git git push -u origin main
3. Adding the Admin Panel as a Submodule in Client Projects
To maintain a single source of truth for the admin panel, we will add it as a Git submodule in each client project.
Steps to Add the Admin Panel as a Submodule
Inside the client project’s root directory:
cd client-project-1
# Add the admin panel repository as a submodule
git submodule add https://github.com/your-org/admin-panel.git admin-panel
# Commit the changes
git add .
git commit -m "Added admin panel as a submodule"
git push origin main
Now, the admin-panel
directory inside client-project-1
is linked to the centralized admin-panel repository.
4. Testing the Admin Panel Endpoints in Each Client Project
After adding the submodule, register the admin panel routes and test the endpoints.
Steps to Load Routes in the Client Project
-
Open
routes/web.php
inclient-project-1
and include the admin panel routes:
require __DIR__.'/admin-panel/routes/web.php';
-
Run the Laravel development server:
php artisan serve
-
Test the admin panel routes in your browser:
http://localhost:8000/admin
5. Making Changes and Propagating Updates
Go to the admin-panel repository on your local machine:
cd path/to/admin-panel
Make your changes (update controllers, models, migrations, etc.), then commit and push:
git add .
git commit -m "Updated admin panel with feature X"
git push origin main
✅ Now, the latest version of the admin panel is available in the repository.
Update the Admin Panel in Each Client Project
Since the admin-panel
is a Git submodule in each client project, you need to pull the latest changes.
Inside client-project-1, update the submodule:
cd client-project-1/admin-panel
git pull origin main
cd ..
git add admin-panel
git commit -m "Updated admin panel submodule to latest version"
git push origin main
Repeat this for client-project-2, client-project-3, etc.
6. Handling Different Client Requirements
Some clients may request custom features that should not be applied to all projects. Here are a few ways to manage this:
Option 1: Use Feature Flags
Use Laravel’s configuration system to enable or disable features for specific clients.
Example in config/admin.php
:
return [
'feature_x_enabled' => env('FEATURE_X_ENABLED', false),
];
Enable it for Client 1 in .env
:
FEATURE_X_ENABLED=true
Option 2: Use Git Branches
-
Create a new branch for a client-specific feature:
git checkout -b client1-custom-feature
-
Make changes and push the branch:
git push origin client1-custom-feature
-
In Client 1’s project, switch to that branch:
cd client-project-1/admin-panel git checkout client1-custom-feature
7. Automating Updates Across Client Projects
If you have multiple client projects, automating updates will save time.
Automate Updates with a Script
Create an update-admin.sh
script to update all client projects at once:
#!/bin/bash
projects=("client-project-1" "client-project-2" "client-project-3")
for project in "${projects[@]}"; do
echo "Updating admin panel in $project..."
cd $project/admin-panel
git pull origin main
cd ..
git add admin-panel
git commit -m "Updated admin panel submodule"
git push origin main
cd ..
done
echo "All projects updated!"
Run the script:
bash update-admin.sh
This ensures that all client projects receive the latest admin panel updates efficiently.
Conclusion
Using Git submodules, you can efficiently manage and update a Laravel admin panel across multiple client projects while maintaining flexibility for individual client customizations. This approach ensures:
✅ Centralized maintenance of the admin panel.
✅ Easy updates across multiple projects.
✅ Ability to handle custom features per client.
Top comments (0)