Laravel Built-in User Auth: Login, Registration and Password Reset
Submitted by nurhodelta_17 on Saturday, November 25, 2017 - 17:39.
Getting Started
First, we're going to create a new project and I'm gonna name it auth and add it to localhost with the name auth.dev. If you have no idea on how to do this, please refer to my tutorial Installing Laravel - PHP Framework.Setting up our Database
1. Open your phpMyAdmin and create a new database. In my case, I've created a database named auth. 2. In our project, open .env file and update the ff lines depending on your setting.
DB_DATABASE=auth
DB_USERNAME=root
DB_PASSWORD=
Migrating
In command prompt, navigate to your project and type: php artisan migrate It will then create our database migration. If you have an error like this: [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes (SQL: alter table `users` add unique ` users_email_unique`(`email`)) You can solve this by opening AppServiceProvider.php located in app/Providers folder. Add this line: use Illuminate\Support\Facades\Schema; In boot add this line: Schema::defaultStringLength(191);Making our Auth
In command prompt, navigate to your project and type: php artisan make:auth It will then create the routes and views for login, registration and password reset. You can modify the html/css of this blades located in resources/views/auth folder. Route:Running our Server
In your web browser, type the name that you added in localhost for your project in my case, auth.dev. You can then register as a new user by click the Register button at the navbar. After registering, you can then proceed to login.Password Reset
First we need to change our Mail Driver into laravel logs so that we can view the link for password reset. In our .env file, change the value of MAIL_DRIVER=log Then, in our login form, click Forgot Your Password? link to go Password Reset Form. After, inputting the user's email, check on laravel.log the reset password link. The laravel.log is located in storage/logs folder. The link should look like this: http://localhost/password/reset/7bf55cf9af57c6a68fe54b2f5dc19061743731e6835b6b7bc0b3fc82ef3b2aed Change the http://localhost in to our project. It will then look like this: auth.dev/password/reset/7bf55cf9af57c6a68fe54b2f5dc19061743731e6835b6b7bc0b3fc82ef3b2aed Paste the link to your browser and you should be able to reset password. That ends this tutorial. Happy Coding :)Add new comment
- 1347 views