laravel-admin增加前台模块
在app/providers里面找到RouteServiceProvider.php添加如下代码
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//注册前台路由
$this->mapProscenium();
}
protected function mapProsceniumRoutes()
{
Route::middleware(config('home.proscenium.route.middleware'))
->namespace(config('home.proscenium.route.namespace'))
->group(config('home.proscenium.directory').DIRECTORY_SEPARATOR.'routes.php');
}
创建config/home并填写下面内容
<?php
return [
'proscenium' => [
'route' => [
'prefix' => 'proscenium',
'namespace' => 'App\\Proscenium\\Controllers',
'middleware' => ['web'],
],
'directory' => app_path('Proscenium'),
]
];
创建Proscenium
其中routes.php的代码为
<?php
use Illuminate\Routing\Router;
Route::group([
'prefix' => config('home.proscenium.route.prefix'),
'middleware' => ['web'],
], function (Router $router) {
//前台首页
$router::get('/index', 'ProsceniumController@index')->name('cm.index');
});
ProsceniumController.php的代码为
<?php
namespace App\Proscenium\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ProsceniumController extends Controller
{
public function index()
{
return view('proscenium.index', ['info' => '你好呀']);
}
}
去resources/views下创建Proscenium文件新建index视图
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>前台首页</title>
<script src="{{ asset('/proscenium/js/jquery-1.9.1.min.js') }}"></script>
</head>
<body>
<div>你好</div>
</body>
<!-- head中需要引入的部分end -->
<script type="text/javascript">
$(function(){
alert("{{ $info }}");
});
</script>
</html>
在视图里面通过
<script src="{{ asset('/proscenium/js/jquery-1.9.1.min.js') }}"></script>
的方法引入对应的样式和js