Skip to content

ソフトウェアエンジニアの技術ブログ:Software engineer tech blog

随机应变 ABCD: Always Be Coding and … : хороший

ソフトウェアエンジニアの技術ブログ:Software engineer tech blog

[Laravel8.15.0]name+passwordでemailをnullableでログイン機能を実装する方法

$ 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がなくなってるから焦ったわ。

Author blogPosted on 2020年11月20日2020年11月20日Categories Laravel Login

Post navigation

Previous Previous post: [JavaScript] 配列・二次元配列・連想配列の違い
Next Next post: [webpack 5.6.0]webpack-dev-server^3.11.0でMODULE_NOT_FOUND


Popular Post [Top 10🔥]

  • Pythonで今月、前月、来月、昨年、毎月あたりを取得する
  • [Laravel8.16.0] 電話と郵便番号のカスタムバリデーション作成
  • phpで予約システムを作くろう2 予約画面
  • [Laravel8.16.0] class内でメンバ変数(共通の変数)を使いたい
  • Laravel フォーム・確認画面の「戻る」ボタンの処理実装
  • Laravel5.7 403エラー forbiddenが出た時
  • Android Studioでのapkファイルの開き方
  • phpmailerで複数アドレス(配列)にBCCで送信
  • bootstrap5でPC版ヘッダーメニューを右寄せにする
  • PROPFINDメソッド

Recent Posts 🐎

  • 【Rust】getblockのCLIコマンド機能を作る
  • 【Rust】getnewaddressのAPI機能を作る
  • 【IPFS】Merkle DAGをPythonで書く
  • 【Ethereum】erc20とethをswap
  • 【Ethereum】送信者が特定の条件の元、ethを送金

Author 🤩

hpscript
Rust, C++, C, Python Go PHP Javascript Java Swift Flutter

Contact form

スクラッチの受託開発を行なっております🖥 ヒヤリング->設計->デザイン ->実装->インフラ構築->運用まで!ブロックチェーン開発します!
・contact

Categories

  • Ada
  • Ajax
  • Algebra
  • Algorithm
  • Amazon SES
  • Android / Java / SQLite
  • Android Layout Design
  • AngularJS
  • ansible
  • apache
  • API
  • app
  • app register
  • AR
  • Arduino
  • Artificial Intelligence
  • assembler
  • audio
  • Auth
  • awk / sed
  • AWS
  • AWS ACM
  • AWS AMI
  • AWS Athena
  • AWS AutoScaling
  • AWS CLI
  • AWS CloudFormation
  • AWS CloudFront
  • AWS CloudWatch
  • AWS CodeDeploy
  • AWS Direct Connect
  • AWS EBS
  • AWS EC2
  • AWS ECS
  • AWS EFS
  • AWS ElastiCache
  • AWS ELB
  • AWS Glacier
  • AWS IAM
  • AWS Kinesis Video Streams
  • AWS lambda, Cloud Front, EFS, EBS
  • AWS RDS
  • AWS Route53
  • AWS S3
  • AWS SNS
  • AWS VPC
  • azure
  • babel
  • backbone.js
  • bash
  • basic
  • batch
  • Bitcoin
  • Blockchain
  • bootstrap
  • Business
  • C
  • C OperatingSystem
  • C#
  • C++
  • CakePHP
  • Canvas
  • Capistrano
  • Carbon
  • Character code
  • Chef
  • CircleCI
  • COBOL
  • CoffeeScript
  • Compiler
  • ComputerVision
  • ComputerVision Biometrics
  • ComputerVision CharacterRecognition
  • ComputerVision Face Detection
  • ComputerVision IR-LED
  • ComputerVision OpenCV
  • ComputerVision ProcessingEngine
  • Cookie
  • CPU
  • cryptocurrency
  • cryptography
  • CSS
  • D3.js
  • data science
  • debugging
  • deep learning
  • deploy
  • Design
  • dev.amazon
  • dev.apple
  • dev.backlog
  • dev.ebay
  • dev.finance
  • dev.google
  • dev.meta
  • dev.microsoft
  • dev.NASA
  • dev.PFN
  • dev.slack
  • dev.twitter
  • dev.watson
  • devOps
  • Devops
  • Django
  • Django Auth
  • Django Database
  • Django Form
  • Django Pagination
  • Django Validation
  • Django View
  • DNS
  • Docker / docker-compose
  • Echo
  • elasticsearch
  • Elasticsearch
  • Electron
  • Electronic Circuit
  • Electronic Circuit flip-flop
  • Embulk
  • enchant.js
  • Ethereum
  • Excel VBA
  • express
  • file
  • filmora
  • Flash
  • flask
  • FlexBox
  • Fluentd
  • Flutter
  • font-awesome
  • front-end
  • GCP
  • Git / GitHub / GitHub Enterprise
  • GitLab
  • GL
  • Go
  • GPU
  • gradle
  • GraphQL
  • grunt
  • gulp
  • Hadoop
  • Hash
  • Heroku
  • HHVM/Hack
  • HTML5
  • HTTPS/HTTP
  • illustrator
  • Image
  • iOS layout
  • ip
  • Java
  • Java servlet
  • JavaScript
  • jenkins
  • jQuery
  • jQuery mobile / jQuery UI
  • jsp
  • k-nn
  • Keras
  • Kernel
  • Kibana
  • Kotlin
  • kubernetes
  • kubernetes minikube
  • Laravel
  • Laravel Chat
  • Laravel Controller
  • Laravel Database
  • Laravel Event
  • Laravel Extra Feature
  • Laravel Forms
  • Laravel Homestead
  • Laravel Jetstream
  • Laravel Login
  • Laravel Mail
  • Laravel Middleware
  • Laravel Migration
  • Laravel Model
  • Laravel Multi-tenant
  • Laravel Package
  • Laravel Paging
  • Laravel Public
  • Laravel Route
  • Laravel Security
  • Laravel Seeding
  • Laravel Storage
  • Laravel Testing
  • Laravel Upgrade
  • Laravel Validation
  • Laravel View
  • LESS
  • Linear Regression
  • Linux
  • Localization
  • log
  • Logstash
  • lsync xinetd/rsync
  • Machine Learning
  • Mackerel
  • mail/smtp/pop/imap
  • Math
  • Memory
  • Mining
  • mobile
  • MongoDB
  • Morphological analysis
  • Motherboard
  • MySQL
  • Natural Language
  • NEM/XEM
  • Netty
  • Network
  • Neural Network
  • New Relic
  • NextJS
  • nginx
  • Node.js
  • Objectiv-C
  • Oracle
  • OS
  • other topics
  • Parallel Processing
  • Perl
  • phantomjs
  • Photography
  • Photoshop
  • PHP
  • physics
  • PostgreSQL
  • Probability
  • processing / p5.js
  • Processor
  • psql
  • pug
  • Python
  • Python library
  • quantum computer
  • R
  • RaspberryPi
  • React Native
  • React.js
  • recognition
  • redis
  • Redmine
  • Redux
  • Research & Development
  • Revel
  • Robot
  • Ruby on Rails
  • Rust
  • sales
  • sass / scss / Compass
  • Scala
  • Security
  • Selenium
  • SEO
  • sesssion
  • Setting up an environment – deploy flow
  • Setting up an environment – development process
  • Setting up an environment – Local Environment
  • shell
  • sinatra
  • sketch
  • Socket.IO
  • software design – basic design
  • software design – DFL
  • software design – entity-relationship diagram
  • software design – flowchart diagram
  • software design – infrastructure
  • software design – Internal Design
  • software design – operation flow
  • software design – screen transition diagram
  • software design – sequence diagram
  • software design – UML
  • software design – WF, screen layout
  • software topics
  • Speaker Recognition
  • Speech Recognition
  • Spring
  • SpringBoot
  • SpringBoot Controller
  • SpringBoot CRUD
  • SpringBoot SpringSecurity
  • SpringBoot Thymeleaf
  • SpringBoot Validation
  • sqlite / MySql / psql
  • ssh
  • SSL/TSL
  • stackmachine
  • statistic
  • storage
  • Stripe
  • struts
  • SVG
  • swagger
  • Swift / SwiftUI
  • swift CoreData
  • Tableau
  • Tailwind css
  • team building
  • TensorFlow
  • Terraform
  • Test
  • three.js
  • Tomcat
  • translation
  • Travis CI
  • TypeScript
  • ubuntu
  • UI/UX
  • uncategorized
  • underscore.js
  • Unit Test / Integration Test
  • unity
  • unix
  • uWSGI
  • VBA
  • Video Streaming
  • Vite
  • vm / vagrant / virtualbox
  • vps
  • VR
  • Vue.js
  • Webpack
  • WebRTC
  • Windows
  • xml
  • YAML / mustache
  • zabbix
  • Zend framework

初めてのSESフリーランス推奨エージェント😤

レバテックフリーランス

ギークスジョブ

ビッグツリーテクノロジー&コンサルティング

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016

Links

- CSDN专业开发者社区
- Google AI blog
- torvalds/linux
- Linux Kernel
- apache/httpd

Recommend Books


ソフトウェアエンジニアの技術ブログ:Software engineer tech blog Proudly powered by WordPress
Posting....