WebDevelpment-Lec 9
WebDevelpment-Lec 9
WebDevelpment-Lec 9
&
Authentication
Lecture 9
Migration
❑ Migration provides a way for easily sharing the schema of the database. It also makes the
modification of the schema much easier.
❑ It gets very useful when you have multiple tables and columns as it would reduce the work over
creating the tables manually.
❑ Create Migration: It can be created by using the artisan command as shown below:
◦ This will create a users table with the following columns: id, name, email, email_verified_at, password,
remember_token, and timestamps.
To Run Migration:
o Before running a migration, we first have to create a MySQL Database and Connect to it.
o After that is done, to Run a Migration, we can use an Artisan command as follows:
o php artisan migrate
Rollback Migration
❑ Thiscommand will run the up() function and create all the tables in the
database for all the migration file in the database/migrations directory.
❑To rollback any last migration which is done, we can use the following
Artisan command:
php artisan migrate:rollback
Laravel Authentication
An Introduction to Laravel Authentication
❑ Most web applications today provide ways for users to reset their passwords.
❑ We will make another route for the forgotten password and create the controller as
we did. Additionally, we will add a route for the reset password link that contains the
token for the entire process:
Route::post('/forgot-password', [ForgotPasswordLinkController::class, 'store’]);
Route::post('/forgot-password/{token}', [ForgotPasswordController::class, 'reset']);
❑ Inside the store method, we will take the email from the request and validate it as we
did.
Resetting Passwords (cont’d)
After this, we can use the SendResetLink . method from the password facade.
And then, as a response, we want to return the status if it succeeded in sending the link or errors
otherwise:
❑ Now that the reset link has been sent to the user’s email, we should
take care of the logic of what happens after that.
❑ We will get the token, email, and new password in the request and
validate them.
❑ After this, we can use the reset method from the password facade to let
Laravel take care of everything else behind the scenes.
❑ We are always going to hash the password to keep it secure.
❑ In the end, we will check if the password was reset, and if it were, we
will redirect the user to the login screen with a success message.
Otherwise, we display an error that it could not be reset:
;
Thank You
&
Good Luck in
your Projects