The following tutorial column ofLaravel Frameworkwill introduce you to how to build multiple sites locally with Laravel. I hope it will be helpful to friends who need it!
##Preface I have a lot of thoughts recently. I want to do this and that. But I encountered a very uncomfortable problem:
api.hellolux.com
One is the background management domain name, I set it as:admin.hellolux.com
implementation Add a new folder in the Controller layer In the app\Http\Controllers directory, add two new folders, namely Api and Admin. Modify the RouteServiceProvider.php file In app\Providers\RouteServiceProvider.php, modify# 新增项目名称的命名空间 protected $AdminNamespace = 'App\Http\Controllers\Admin'; protected $ApiNamespace = 'App\Http\Controllers\Api'; public function map() { # 根据项目名称定义路由 $this->mapApiRoutes(); $this->mapAdminRoutes(); } # 新增两个方法 protected function mapAdminRoutes() { Route::group([ 'domain' => config('app.admin_domain'), 'namespace' => $this->AdminNamespace, ], function ($router) { require base_path('routes/admin.php'); }); } protected function mapApiRoutes() { Route::group([ 'domain' => config('app.api_domain'), 'namespace' => $this->ApiNamespace, ], function ($router) { require base_path('routes/api.php'); }); }
'api_domain' => env('API_DOMAIN', 'api.hellolux.com'), 'admin_domain' => env('ADMIN_DOMAIN', 'admin.hellolux.com'),
API_DOMAIN=api.hellolux.com ADMIN_DOMAIN=admin.hellolux.com
# api.php use Illuminate\Http\Request; Route::get('/', "IndexController@index"); # admin.php use Illuminate\Http\Request; Route::get('/', "IndexController@index");
# Local_Manage 127.0.0.1 api.hellolux.com 127.0.0.1 admin.hellolux.com
Include /private/etc/apache2/extra/httpd-vhosts.conf
ServerAdmin hellolux@163.com DocumentRoot "/Users/hellolux/Documents/Github/Local_Manage/public" ServerName hellolux ServerAlias *.hellolux.com ErrorLog "/Users/hellolux/Documents/Github/Local_Manage/logs/error.log" CustomLog "/Users/hellolux/Documents/Github/Local_Manage/logs/access.log" common
sudo apachevtl restart
The above is the detailed content of How to build multiple sites locally in Laravel. For more information, please follow other related articles on the PHP Chinese website!