laravel前后台路由分离 - 子钦加油 - 博客园


本站和网页 https://www.cnblogs.com/zmdComeOn/p/10250898.html 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

laravel前后台路由分离 - 子钦加油 - 博客园
首页
新闻
博问
专区
闪存
班级
我的博客
我的园子
账号设置
简洁模式 ...
退出登录
注册
登录
子钦加油
博客园
1.博客园美化
1.1、三级菜单一
1.2、三级菜单二
2.博客园自定义导航
我的首页
全部分类
0.PHP
1.Python基础
2.Django基础教程
3.Django项目
4.REST framework
5.CRM客户关系管理
6.前端
7.数据库
8.python进阶
9.数据库
10.爬虫
11.Laravel
12.Linux
13.Pycharm基础知识
14.微信小程序
Flask基础
1.快速入门
2.请求扩展和数据库连接池
3.信号和wtforms
4.SQLAlchemy
Python基础
1.简介
2.数据类型
3.文件操作
4.迭代器生成器装饰器
5.函数
6.内置函数
7.常用模块
更多
Django基础
1.安装与运行
2.路由规则
3.Model
4.模板语言与分页
5.Cookie
6.Session
7.CSRF 中间件
8.django-xadmin
更多
项目相关
1.REST framework 源码分析
2.用户注册和登录系统
3.在线教育平台
4.生鲜超市
5.CRM客户关系管理
6.Flask构建微电影
更多
Python进阶
1.魔法函数
2.深入类和对象
更多
Python爬虫
1.urllib和urllib2
2.Opener和Requests
3.XPATH和BeautifulSoup4
4.利用多线程爬虫
5.Selenium模拟用户操作
6.Scrapy框架原理介绍
7.Spider类
更多
前端知识
1.HTML
2.CSS
3.Javascript
4.Dom
5.Jquery
6.Jquery实例
7.Ajax
8.RGB色阶对照表
更多
学习资源
0.Python基础教程
1.Django2.0官网
2.REST framework官网
3.Flask文档
4.Bootstrap教程
5.总有你要的书单
6.python中文学习大本营
7.爬虫学习博客
8.The
Flask Mega-Tutorial
9.表设计工具
10.Flask extensions
11.Vue2.0官方文档
12.Dajngo优秀资源
13.Scrapy中文文档
14.小程序社区
15.python资源大全
16.selenium文档
17.layer API帮助文档
18.Django教程
19.Flask大型项目教程
娱乐休闲
1.全景图片欣赏
小程序框架-组件
1.WEPY 框架文档
2.MpVue 框架文档
3.Taro 框架文档
4. vant-weapp文档
扩大
缩小
子钦加油
laravel前后台路由分离
在laravel中创建文件放置前台和后台控制器
找到app/providers/RouteServiceProvider.PHP文件
在内配置
例:
<?php
namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
/**
* This namespace is applied to the controller routes in your routes file.
* In addition, it is set as the URL generator's root namespace.
* @var string
*/
protected $namespace = 'App\Http\Controllers';
protected $frontendNamespace;
/**
* Define your route model bindings, pattern filters, etc.
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
//
$this->frontnamespace = 'App\Http\Controllers\Front';
parent::boot($router);
/**
* Define the routes for the application.
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
//配置路由所在文件
// $backendUrl = config('route.backend_url');
// $frontendUrl = config('route.frontend_url');
// $apiUrl = config('route.api_url');
//
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
//前台
$router->group(['namespace' => $this->frontnamespace], function ($router)
// 'domain' => $backendUrl,
require app_path('Http/routes_front.php');
});
<?php
namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
/**
* This namespace is applied to the controller routes in your routes file.
* In addition, it is set as the URL generator's root namespace.
* @var string
*/
protected $namespace = 'App\Http\Controllers';
protected $backendNamespace;
protected $frontendNamespace;
protected $apiNamespace;
protected $currentDomain;
/**
* Define your route model bindings, pattern filters, etc.
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
//
$this->backendNamespace = 'App\Http\Controllers\Backend';
$this->frontendNamespace = 'App\Http\Controllers\Frontend';
$this->apiNamespace = 'App\Http\Controllers\API';
// $this->currentDomain = $this->app->request->server->get('HTTP_HOST');
$this->currentDomain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : "";
parent::boot($router);
/**
* Define the routes for the application.
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
// $router->group(['namespace' => $this->namespace], function ($router) {
// require app_path('Http/routes.php');
// });
$backendUrl = config('route.backend_url');
$frontendUrl = config('route.frontend_url');
$apiUrl = config('route.api_url');
switch ($this->currentDomain) {
case $apiUrl:
// API路由
$router->group([
'domain' => $apiUrl,
'namespace' => $this->apiNamespace],
function ($router) {
require app_path('Http/routes-api.php');
);
break;
case $backendUrl:
// 后端路由
$router->group([
'domain' => $backendUrl,
'namespace' => $this->backendNamespace],
function ($router) {
require app_path('Http/routes-backend.php');
);
break;
default:
// 前端路由
$router->group([
'domain' => $frontendUrl,
'namespace' => $this->frontendNamespace],
function ($router) {
require app_path('Http/routes-frontend.php');
);
break;
完成后我们的路由也可以新建了 但要和上面的名称要一样
在路由中可以这样写(当然也可以自定义路由)例:
个人主页
Route::group(['middleware' => ['web']], function () {
Route::controller('/test', 'TestController');
// 重置
Route::get('user/password/reset/{token?}', [
'as' => 'user.password.reset@token',
'uses' => 'User\PasswordController@getReset'
]);
]);
转自woshihaiyong168的博客
作者:子钦加油
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年
您的资助是我最大的动力!金额随意,欢迎来赏!
如果,想给予我更多的鼓励,求打
posted on
2019-01-10 16:42
子钦加油
阅读(1823)
评论(0)
编辑
收藏
举报
刷新评论刷新页面返回顶部
导航
博客园
首页
新随笔
联系
管理
Powered by:
博客园
Copyright 2022 子钦加油
Powered by .NET 7.0 on Kubernetes
返回顶部