PSR4自动载入规则
命名规则App\Admin\Controller
在路由中include_once('路由名字') ,可以调用其他路由文件的路由
路由中间件:
Laravel 中间件提供了一种方便的机制来过滤进入应用的HTTP请求。例如,Laravel 内置了一个中间件来验证用户的身份认证 ,
如果没有通过身份认证,中间件会将用户重定向到登陆界面,但是,如果用户被认证,中间件将允许该请求进一步进入该应用。
当然,除了身份认证以外,还可以编写另外的中间件来执行各种任务,例如:CORS中间件可以负责为所有离开应用的响应添加合适的头部信息:
Route::get('/',function(){return redirect("/login");}); //自动跳转登录页面
Route::get('/login', "\App\Http\Controllers\LoginController@index")->name('login');//定义登录路由
Route::group(['middleware'=>'auth:web'],function () {
...路由
嵌入adminlte 皮肤
https://github.com/almasaeed2010/AdminLTE/
composer require “almasaeed2010/adminlte=~2.0“
用户认证:
需要在config/auth中
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admin' => [
'driver' => 'eloquent',
'model' => App\AdminUser::class,
],
如果是新定义的验证
视图中
\Auth::guard("admin")->user()->name
控制器中
\Auth::guard("admin")->attempt($user)
分页:
视图中
{{$users->links()}}
修改表状态
class AlterPostsTable extends Migration
{
public function up()
{
Schema::table("posts",function (Blueprint $table){
$table->tinyInteger('status')->default(0);
//文章的状态,0未知/1通过/-1删除
});
}
public function down()
{
Schema::table("posts",function (Blueprint $table){
$table->dropColumn('status'); //删除字段
});
}
}