Sav*_*age 7 laravel laravel-5 laravel-authorization laravel-authentication
我想更改laravel auth 表的表名和一些列名。
我要采取哪些步骤或编辑哪些代码而不破坏某些内容?
我以前试过这个,注册成功了,但登录没有。每当我尝试登录时,我都会被重定向回登录页面。
小智 10
您可以按照以下给定的步骤操作:
Authenticatableemail输入文本字段名称更改为email_address.通过以上所有步骤,我们已经准备好View部分,现在让我们开始自定义Auth
现在打开config/auth.php
'model' => App\User::class,为'model' => App\Account:class内部providers数组。现在我们需要在app/Http/Auth/LoginController.php 中添加新函数,如下所示:
public function username(){ return 'email_address'; // this string is column of accounts table which we are going use for login }
现在我们完成了所有调整,您可以测试功能。
我已经测试了它的功能和它的魅力:)
您必须在您的帐户模型中扩展“Illuminate\Foundation\Auth\User”。
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Account extends Authenticatable
{
use Notifiable;
//code here
public function getEmailAttribute() {
return $this->email_addr;
}
public function setEmailAttribute($value)
{
$this->attributes['email_addr'] = strtolower($value);
}
}
Run Code Online (Sandbox Code Playgroud)
并在提供者数组中的“config/auth.php”中更改配置文件
'users' => [
'driver' => 'eloquent',
'model' => App\Account::class, //replace User to Account
],
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13163 次 |
| 最近记录: |