【发布时间】:2018-08-03 00:39:51
【问题描述】:
首先,我看过这个主题(以及许多其他主题):
Laravel Auth::attempt() always false?
Laravel 5 Auth:attempt() always returns false
但我一直无法登录我的应用程序。我正在使用 Laravel 5.6,我的表名为 oc_users。
DB::table('oc_users')->insert(
[
'email' => 'myemail@gmail.com',
'pwd' => bcrypt('123456'),
'active' => true
]);
我转到文件 Laravel > App > User.php 并更改为:
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $table = 'oc_users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['email', 'pwd'];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = ['pwd', 'remember_token'];
}
以及执行登录的代码:
public function form_login(Request $request)
{
if($request->filled('email') == FALSE || $request->filled('pwd') == FALSE)
return Redirect::back()->withErrors('Fill the credentials');
if (Auth::attempt(['email' => $request->email, 'pwd' => $request->pwd]))
return redirect()->intended('app');
return Redirect::back()->withErrors('Email or password wrong');
}
我还去了文件 App > Config > Auth.php 试图弄清楚是否有一个表我需要更改,但它似乎在 Laravel 5.6 中不存在
【问题讨论】:
-
您能发布您的
oc_users表的架构创建吗?