項目用到的前端庫hdjs網(wǎng)址hdjs.hdphp.com
一赤拒、安裝提示增強工具Laravel-ide-helper
1、下載:composer? require barryvdh/laravel/laravel-ide-helper
2隘冲、在app.php下? providers添加:Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
3、php artisan ide-helper:generate(如果沒有效果重新啟動IDE,Phpstorm)
二绑雄、數(shù)據(jù)填充與數(shù)據(jù)遷移
1展辞、創(chuàng)建hd表
php artisan make:migration create_tb_table --create=hd
2、創(chuàng)建模型并創(chuàng)建表
php artisan make:model Model/Admin -m
3.使用tinker與factory創(chuàng)建管理員初始數(shù)據(jù)
php artisan tinker
factory (App\Model\Admin\::class,3)->create();
4.數(shù)據(jù)回滾
php? ?artisan? ?migrate:rollback
三万牺、解決mysql5.7以下版本不能數(shù)據(jù)遷移兩種解決方案
1罗珍,
config文件夾下database.php
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
修改
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
2、
app/Providers文件夾下
AppServiceProvider.php
use Schema;
public? function boot()
{
Schema::defaultStringLength(191);
}
四脚粟、使用用戶認證系統(tǒng)與獨立設(shè)置guard進行登錄處理
在config/auth.php?
'guards'=>[],
添加
'admin' => [
? ? 'driver' => 'session',
? ? 'provider' => 'admins',
],
在'providers' => [],
添加
'admins' => [
? ? 'driver' => 'eloquent',
? ? 'model' => App\Model\Admin::class,
],
在Model層添加
use Illuminate\Foundation\Auth\User;
模型繼承User
五覆旱、使用中間件mideleware進項行權(quán)限登錄驗證
1、創(chuàng)建中間件
php artisan make:middleware AdminMiddleware
2核无、找到? Http\Middleware下的AdminMiddleware.php
引入 use Auth;?
?添加判斷
if(!Auth::guard('admin')->check()){
? ? return redirect('/admin/login');
}
3扣唱、找到Http\kernel.php
在路由中間件 $routeMiddleware添加
'admin.auth'=>AdminMiddleware::class,
4.使用
在登錄類
public function __construct()
{
? ? $this->middleware('admin.auth')->except(['loginForm','login']);
//excepts是哪個方法不執(zhí)行
}
六、退出報錯
QueryException?in?Connection.php line 647:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'remember_token' in 'field list' (SQL: update `admins` set `remember_token` = 4rwLxz0HkIuhgE5DTojXqQ7OrE9IZcBae3vIgKfijsxtVMr33SDdvi7aGrhg where `id` = 1)
在Admin.php
添加
protected $rememberTokenName = ' ';
七团南、使用Request請求驗證&bootstrap進行表單驗證處理
php artisan make? request? AdminPost
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Auth;
use Validator;
use Hash;
class AdminPost extends FormRequest
{
? ? /**
* Determine if the user is authorized to make this request.
*
? ? * @return bool
*/
? ? public function authorize()
{
? ? ? ? return Auth::guard('admin')->check();
}
? ? /**
* 添加驗證規(guī)則
*/
? ? public function addValidator()
{
? ? ? ? //驗證用戶密碼
? ? ? ? Validator::extend('check_password', function ($attribute, $value, $parameters, $validator) {
? ? ? ? ? ? return Hash::check($value, Auth::guard('admin')->user()->password);
});
}
? ? /**
* Get the validation rules that apply to the request.
*
? ? * @return array
*/
? ? public function rules()
{
? ? ? ? $this->addValidator();
? ? ? ? return [
? ? ? ? ? ? 'password'? ? ? ? ? ? ? => 'sometimes|required|confirmed',
? ? ? ? ? ? 'password_confirmation' => 'sometimes|required',
? ? ? ? ? ? 'original_password'? ? => 'sometimes|required|check_password',
];
}
? ? /**
* 中文提示
*
? ? * @return array
*/
? ? public function messages()
{
? ? ? ? return [
? ? ? ? ? ? 'password.required'? ? ? ? ? ? ? ? => '新密碼不能為空',
? ? ? ? ? ? 'password_confirmation.required'? => '確認密碼不能為空',
? ? ? ? ? ? 'password.confirmed'? ? ? ? ? ? ? => '兩次密碼輸入不一致',
? ? ? ? ? ? 'original_password.required'? ? ? => '原密碼輸入錯誤',
? ? ? ? ? ? 'original_password.check_password' => '原密碼輸入錯誤',
];
}
}
八噪沙、組件提示消息flash
1、安裝
composer require laracasts/flash
2吐根、添加到app.php? ?providers下
Laracasts\Flash\FlashServiceProvider::class,
3正歼、master.blade.php引入
@include(‘flash::message’)
添加
require(['bootstrap'],function ($) {
$('#flash-overlay-modal').modal();
});
4、執(zhí)行
php artisan vendor:publish --provider="Laracasts\Flash\FlashServiceProvider"
九拷橘、創(chuàng)建資源管理器
php artisan make:controller Admin\TagController --resource