在实行前后台分离时,使用artisan时出现Undefined index: HTTP_HOST


<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
//protected $namespace = 'App\Http\Controllers';

protected $authorNamespace = 'App\Http\Controllers\Author';

protected $homeNamespace = 'App\Http\Controllers\Home';

protected $apiNamespace = 'App\Http\Controllers\Api';

/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//

parent::boot();
}

/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
//$this->mapApiRoutes();

//$this->mapWebRoutes();


$sld_prefix = explode('.',$_SERVER['HTTP_HOST'])[0];
if(config('route.api_url') == $sld_prefix){
$this->mapApiRoutes();
}elseif(config('route.author_url') == $sld_prefix){
$this->mapAuthorRoutes();
}elseif(config('route.home_url') == $sld_prefix){
$this->mapHomeRoutes();
}

}

/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}


/**
* 管理后台
*/
protected function mapApiRoutes()
{
Route::middleware('web')
->namespace($this->apiNamespace)
->group(base_path('routes/api.php'));
}

/**
* 管理作者
*/
protected function mapAuthorRoutes()
{
Route::middleware('web')
->namespace($this->authorNamespace)
->group(base_path('routes/author.php'));
}

/**
* 管理前台
*/
protected function mapHomeRoutes()
{
Route::middleware('web')
->namespace($this->homeNamespace)
->group(base_path('routes/home.php'));
}

}

点赞 取消点赞 收藏 取消收藏

<< 上一篇: 请问PHP7.2 ZEND内核中zend_read_property中的最后一个zval *rv参数是代表什么意思?

>> 下一篇: 在Laravel5.5中怎么使用MAIL_ENCRYPTION=starttls发送邮件