第一步:添加apphttpControllers文件夹里面创建我们要存放前端和后端或者接口的文件夹
列如: Home(前端) Admin(后端) App(接口) 文件夹
![36c53269c3f09be5f1fc15f65230c05c.png](https://i-blog.csdnimg.cn/blog_migrate/420392261c5900242c6f1b4b6dac08be.png)
第二步:修改apphttpprovidersRouteServiceProvider.php
- <?php
- namespace AppProviders;
- use IlluminateSupportFacadesRoute;
- use IlluminateFoundationSupportProvidersRouteServiceProvider 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 = 'AppHttpControllers';
- protected $homeNamespace = 'AppHttpControllersHome';//PC端
- protected $adminNamespace = 'AppHttpControllersAdmin';//管理后台
- /**
- * 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.admin_url') == $sld_prefix){
- $this->mapAdminRoutes();
- }elseif(config('route.home_url') == $sld_prefix){
- $this->mapHomeRoutes();
- }elseif(config('route.api_url') == $sld_prefix){
- $this->mapApiRoutes();
- }
- }
- /**
- * 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'));
- }
- /**
- * Define the "api" routes for the application.
- *
- * These routes are typically stateless.
- *
- * @return void
- */
- protected function mapApiRoutes()
- {
- Route::prefix('api')
- ->middleware('api')
- ->namespace($this->namespace)
- ->group(base_path('routes/api.php'));
- }
- /**
- * 管理后台
- */
- protected function mapAdminRoutes()
- {
- Route::middleware('web')
- ->namespace($this->adminNamespace)
- ->group(base_path('routes/admin.php'));
- }
- /**
- * PC端
- */
- protected function mapHomeRoutes()
- {
- Route::middleware('web')
- ->namespace($this->homeNamespace)
- ->group(base_path('routes/home.php'));
- }
- }
第三步:在config下创建文件route.php,并在里面添加:
- <?php
- return array(
- 'admin_url'=>'admin',
- 'home_url'=>'www',
- 'api_url'=>'api'
- );
第四步:在routes目录下创建admin.php 和home.php 路由
![67303080fbe7c8a151a0a6335f51e7e9.png](https://i-blog.csdnimg.cn/blog_migrate/79a221878d13739661fc1aac136d9140.png)
第五步:分别在appHttpControllersAdmin和appHttpControllersHome
- <?php
- namespace AppHttpControllersAdmin;
- use AppHttpControllersController;
- class AdminController extends Controller
- {
- public function index()
- {
- echo "this is admin";
- }
- }
- <?php
- namespace AppHttpControllersHome;
- use AppHttpControllersController;
- class HomeController extends Controller
- {
- public function index()
- {
- echo "this is home";
- }
- }
第六步:分别在admin.php 和home.php 新建路由
- Route::get('/', 'AdminController@index');
- 2.Route::get('/','HomeController@index');
第七步:添加nginx配置日志
- server {
- listen 80;
- listen 443 ssl;
- server_name
The PHP Framework For Web Artisans
admin.laravel.com;
- charset utf-8;
- #access_log logs/www.polypm.com.cn.access.log main;
- root /data/webroot/http://kangsf.com.cn/public;
- index index.html index.php;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- ssl_certificate ssl/cert.pem;
- ssl_certificate_key ssl/cert.key;
- location / {
- try_files $uri $uri/ /index.php?$args;
- }
- # redirect server error pages to the static page /50x.html
- #
- #error_page 500 502 503 504 /50x.html;
- #location = /50x.html {
- # root html;
- #}
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ .php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:5443
- #
- location ~ .php$ {
- fastcgi_pass 127.0.0.1:7113;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /.ht {
- # deny all;
- #}
- }
第八步:测试
![3f0157105a3143ac1f1d457d625a563e.png](https://i-blog.csdnimg.cn/blog_migrate/e513fdff3462e5b5acc24344e42ccab4.jpeg)
![bdc44683ab3ae2de7710f646922e496c.png](https://i-blog.csdnimg.cn/blog_migrate/e2b499f875d74142bb3bfe6a7fff2a88.jpeg)
读者福利,可直接点击链接领取相关学习福利包:
石墨文档
石墨文档-远程办公系统/解决方案_多人协同办公软件_远程在线办公/协作工具shimo.im![2dd15bb6b8b131e2d9e662af45a82897.png](https://i-blog.csdnimg.cn/blog_migrate/6d066145ed5acfe91fd9e08803d05f7a.png)
是安全网站放心,继续访问就可以领取了哦