Chapter 9. User Authentication and Authorization
Setting up a basic user authentication system—including registration, login, sessions, password resets, and access permissions—can often be one of the more time-consuming pieces of creating the foundation of an application. It’s a prime candidate for extracting functionality out to a library, and there are quite a few such libraries.
But because authentication needs can vary widely across projects, most authentication systems grow bulky and unusable quickly. Thankfully, Laravel has found a way to make a suite of authentication systems that are easy to use and understand, but flexible enough to fit in a variety of settings.
Every new installation of Laravel has a create_users_table
migration and a User
model built in. If you bring in Breeze (see “Laravel Breeze”) or Jetstream (see “Laravel Jetstream”), they’ll seed your app with a collection of authentication-related views, routes, controllers/actions, and other features. The APIs are clean and clear, and the conventions all work together to provide a simple—and seamless—authentication and authorization system.
The User Model and Migration
When you create a new Laravel application, the first migration and model you’ll see are the create_users_table
migration and the App\User
model. Example 9-1 shows, straight from the migration, the fields you’ll get in your users
table.
Example 9-1. Laravel’s default user migration
Schema
::
create
(
'users'
,
function
(
Blueprint
$table
)
{
$table ...
Get Laravel: Up & Running, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.