$ php -v
PHP 7.4.11 (cli) (built: Oct 21 2020 19:12:26) ( NTS )
### プロジェクト作成
$ composer create-project –prefer-dist laravel/laravel nonemail
$ cd nonemail
$ composer require laravel/jetstream
$ php artisan jetstream:install livewire
mysql> create database nonemail;
.env
DB_DATABASE=nonemail
$ php artisan migrate
$ npm install && npm run dev
### nameでログインできるようにする
config/fortify.php
'username' => 'name',
resources/views/auth/login.blade.php
<div>
<x-jet-label for="name" value="{{ __('Name') }}" />
<x-jet-input id="name" class="block mt-1 w-full" type="name" name="name" :value="old('name')" required autofocus />
</div>
$ php artisan serve –host 192.168.33.10 –port 8000
// 動作確認
// L registerしてログアウト後、nameでログインできるか確認
$ php artisan make:migration change_users_table_column_email_nullable –table=users
2020_11_20_024033_change_users_table_column_email_nullable.php
public function up()
{
Schema::table('users', function (Blueprint $table) {
//
$table->dropUnique('users_email_unique');
$table->string('name')->unique()->change();
$table->string('email')->nullable()->change();
});
}
$ composer require doctrine/dbal
$ php artisan migrate
mysql> describe users;
+—————————+—————–+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+—————————+—————–+——+—–+———+—————-+
| id | bigint unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| email | varchar(255) | YES | | NULL | |
| email_verified_at | timestamp | YES | | NULL | |
| password | varchar(255) | NO | | NULL | |
| two_factor_secret | text | YES | | NULL | |
| two_factor_recovery_codes | text | YES | | NULL | |
| remember_token | varchar(100) | YES | | NULL | |
| current_team_id | bigint unsigned | YES | | NULL | |
| profile_photo_path | text | YES | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+—————————+—————–+——+—–+———+—————-+
12 rows in set (0.00 sec)
app/Actions/Fortify/CreateNewUser.php
L nameを’required’, ‘unique:users’にする
L emailから’required’を削除し、’nullable’を追加
public function create(array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255', 'unique:users'],
'email' => ['nullable', 'string', 'email', 'max:255'],
'password' => $this->passwordRules(),
])->validate();
return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}
### tinkerで入れる場合
php artisan tinker
$user = new App\Models\User();
$user->password = Hash::make(‘password’);
$user->name = ‘yamada’;
$user->save();
### sql文で入れる場合
passwordをhash化する
$hashedpassword = password_hash('fugagua', PASSWORD_DEFAULT);
hash化したパスワードをインサート
INSERT INTO users (name, password, created_at, updated_at) VALUES (“ito”, “$2y$10$1Wix04F*********”, “2020-11-20 03:23:47”, “2020-11-20 03:23:47”);
以下のようにhash化せずにinsertするとログインできないので注意
INSERT INTO users (name, password, created_at, updated_at) VALUES (“ito”, “fugafuga”, “2020-11-20 03:23:47”, “2020-11-20 03:23:47”);
なるほど、8系はLoginControllerがなくなってるから焦ったわ。