반응형
Laravel 10 Auth::attempt 를 쓸려고 보니까 잘 안된다..
xdebug로 까보니 인증쪽 credentials하는 부분에서 user가 null로 넘어온다..
뭐여...
User 모델에 있는 인증 소스와 똑같이 Extends로 선언하고
getAuthPassword에 필드이름을 적어준다.
https://github.com/laravel/laravel/blob/10.x/app/Models/User.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable, HasFactory;
protected $hidden = [
'Password',
];
public function getAuthPassword() {
return $this->Password;
}
}
기본 필드는 password로 선언되어있다.
attempt 선언시 첫번째 필드에 인증에 사용될 ID 필드를 선언하고
두번째 필드는 기존대로 password로 넘겨준다.
$credentials = ['ID' => $this->email, 'password'=> $this->password];
// dd($credentials);
if(Auth::attempt($credentials)) {
return redirect()->route('counter');
}
잘된다.
반응형
'Infomation' 카테고리의 다른 글
Laravel PHP CS Fixer 대체 Laravel Pint (09.21 수정) (0) | 2023.09.21 |
---|---|
LiveWire3 SweetAlert2 사용하기 (0) | 2023.09.18 |
Chrome-php Operation timed out after 5s error (0) | 2023.08.17 |
Mac Webp 변환 빠른동작 Script 등록 (0) | 2023.05.22 |
[Chrome Extension] Google, Namuwiki tabs.onUpdated Duplicate (0) | 2023.05.19 |