laravel5.5 调用系统自带登陆认证auth
Posted ヽ坚强的蘑菇
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel5.5 调用系统自带登陆认证auth相关的知识,希望对你有一定的参考价值。
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‘);
}
}
以上是关于laravel5.5 调用系统自带登陆认证auth的主要内容,如果未能解决你的问题,请参考以下文章