laravel 实现划分admin和home 模块分组
作者:hlyy8_2018 时间:2024-05-22 10:02:03
我们使用tp或者yii2的时候,会将网站的前台和后台按照模块分组。yii2的高级模板已经帮我们划分好了,tp系列框架需要自己配置分组。那么laravel5该怎么划分这样的模块呢?
routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
//默认控制器
Route::get('/', 'Home\IndexController@index');
//前台路由组
Route::group(['namespace' => 'Home'], function(){
// 控制器在 "App\Http\Controllers\Home" 命名空间下
Route::get('/', [
'as' => 'index', 'uses' => 'IndexController@index'
]);
});
//后台路由组
Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function(){
// 控制器在 "App\Http\Controllers\Admin" 命名空间下
Route::get('/', [
'as' => 'index', 'uses' => 'IndexController@index'
]);
});
设置了命名空间,admin后台控制器,统一加了admin前缀。并且设置了默认访问的控制器,Home文件夹下的Index控制器的index方法。
Home\IndexController.php
<?php
/**
* author: NickBai
* createTime: 2017/2/6 0006 上午 9:05
*/
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Controller;
class IndexController extends Controller
{
public function index()
{
return 'this is home';
}
}
Admin\IndexController.php
<?php
/**
* author: NickBai
* createTime: 2017/2/6 0006 上午 9:03
*/
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
class IndexController extends Controller
{
public function index()
{
return 'this is admin';
}
}
此时访问 domain(你的域名)即可访问前台,domain/admin 即可访问admin后台
来源:https://blog.csdn.net/hlyy8_2018/article/details/82284170
标签:laravel,admin,home,分组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python可视化单词统计词频统计中文分词的实现步骤
2023-10-24 17:16:49
![](https://img.aspxhome.com/file/2023/4/85164_0s.jpg)
在MySQL中使用更新日志文件
2009-02-26 16:22:00
ajax在js中和jQuery中的用法实例详解
2024-02-26 06:12:31
十分钟教会你用Python处理CSV文件
2022-02-05 02:24:12
![](https://img.aspxhome.com/file/2023/3/121633_0s.png)
简单掌握Python的Collections模块中counter结构的用法
2023-05-17 00:20:13
JavaScript实现简单计算器小程序
2024-05-02 16:28:39
![](https://img.aspxhome.com/file/2023/4/130484_0s.jpg)
关于sql和mysql对于别名不能调用的一些理解
2024-01-26 16:34:15
禁止背景图在网页中平铺
2011-04-29 14:10:00
![](https://img.aspxhome.com/file/UploadPic/20072/2007231139890s.gif)
vue项目配置element-ui容易遇到的坑及解决
2024-04-29 13:10:25
![](https://img.aspxhome.com/file/2023/8/132908_0s.png)
怎么样在网页上读取远程xml的数据
2008-10-10 17:43:00
使用 Django Highcharts 实现数据可视化过程解析
2022-12-27 19:18:51
![](https://img.aspxhome.com/file/2023/8/99238_0s.png)
python3 图片 4通道转成3通道 1通道转成3通道 图片压缩实例
2021-04-01 05:54:41
go HTTP2 的头部压缩算法hpack实现详解
2024-05-21 10:27:37
![](https://img.aspxhome.com/file/2023/5/123975_0s.png)
程序员的七夕用30行代码让Python化身表白神器
2023-10-26 12:27:41
![](https://img.aspxhome.com/file/2023/3/113153_0s.png)
python实现redis三种cas事务操作
2022-08-27 01:50:59
那些看一眼就让你难忘的广告
2007-09-21 19:46:00
![](https://img.aspxhome.com/file/UploadPic/20079/21/2007921195335406s.jpg)
javascript判断网页是关闭还是刷新
2024-02-23 21:05:52
解决新版Pycharm中Matplotlib图像不在弹出独立的显示窗口问题
2023-06-28 02:44:14
![](https://img.aspxhome.com/file/2023/5/61455_0s.jpg)
Python实现的使用telnet登陆聊天室实例
2023-11-17 10:41:17
![](https://img.aspxhome.com/file/2023/8/112988_0s.png)
Python对FTP交互封装的实现
2023-05-18 15:12:14