Laravel - トラブルシュート - Laravel 12 - The provided password is incorrect


クラウディア 


1. 概要
2. テーブル設定

1. 概要

 実は、これ、日本語化しているので「ID、またはパスワードが一致しません。」と表示させています。  ユーザ管理テーブルは、デフォルトでは「users」なのですが・・・。  別のテーブルを使っていて、空っぽの「users」を「select」しているために、ログインできないのです。  本ページは、下記のサイトを参考にさせていただきました。
Laravel で標準の Users テーブルからテーブル名を変更して認証を行う際に修正が必要なファイル #PHP

2. テーブル設定


vi [project path]app/Models/User.php
 デフォルトで、下記のように書かれています。

<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    /** @use HasFactory<\Database\Factories\UserFactory> */
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var list<string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }
}
 14行目あたりに、下記の行を追加します。

    protected $table = 'TableName';
    protected $primaryKey = 'PrimaryKeyColumn';
 上から、ログインユーザ管理をしているテーブル名、プライマリキーとなるカラム名を設定します。