1执行命令 php artisan make:auth 2 编辑文件 config/auth guardes ‘admin‘ => [ ‘driver‘ => ‘session‘, ‘provider‘ => ‘admins‘, ], providers ‘admins‘ => [ ‘driver‘ => ‘eloquent‘, ‘model‘ => App\Model\Admin::class, ], 3 创建model文件 php artisan make:model Model/Admin 4 创建数据库 CREATE TABLE `admin` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO admin (`id`, `username`, `email`, `password`, `remember_token`, `created_at`, `updated_at`) VALUES (‘2‘, ‘admin‘, ‘[email protected]‘, ‘$2y$10$3eSGes8MbhpCvu.WwAEfNuMaWuhJ6dyFM9EkHussBr0WYfRsFtJ8q‘, ‘WlcBHvBBeAF6rso9uDkcgNCmj1ivpsGbNjY5xQ61tBJKtWAOboi44upUaqdI‘, ‘2018-05-05 14:33:03‘, ‘2018-05-05 09:13:20‘); 初始化登陆的用户名和密码 5 编辑控制器
<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller;use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller{ /* |-------------------------------------------------------------------------- | Login Controller |-------------------------------------------------------------------------- | | This controller handles authenticating users for the application and | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | */ use AuthenticatesUsers; /** * Where to redirect users after login. * * @var string */ protected $redirectTo = ‘/index/‘; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware(‘guest‘)->except(‘logout‘); } public function username() { return ‘username‘; } //加载自定义的guard protected function guard() { return Auth::guard(‘admin‘); }}
原文地址:https://www.cnblogs.com/jackspider/p/8994486.html
时间: 2024-11-02 07:25:17