There are lots of packages available to authenticate the APIs request in Laravel. Such as Passport, **JWT, **and Sanctum. We are already familiar with **Laravel Passport **and JWT (JSON Web Token) to authenticate the APIs. Sanctum is introduced in Laravel 7 and really this is also a secured package. The Sanctum provides the authentication for the **SPA **(Single Page Application)mobile application, and the token-based APIs. In this post, we will be creating the Laravel 8 Sanctum auth for the token-based APIs. I have already shared the tutorial for creating  RESTful APIs using Passport Authentication. The main difference between passport and sanctum is passport usage OAuth for the authentication. But, Sanctum generates the API tokens without the complication of OAuth.

Contents

  • 1 Prerequisites
  • 2 Create Project For Laravel 8 Sanctum Auth APIs
  • 3 Create and Configure a Database
  • 4 Install Laravel 8 Sanctum Authentication
  • 5 Publish Sanctum Configuration
  • 6 Add Models and Migrations
  • 7 Add Mass Assignment For the Models
  • 8 Add Sanctum Authentication Guard
  • 9 Create Controllers
  • 10 Add Routes
  • 11 Test APIs Result
  • 11.1 1. User Sign Up
  • 11.2 2. User Login
  • 11.3 3. User Detail
  • 11.4 3. Create Task
  • 11.5 4. Fetch Tasks
  • 11.6 5. Task Detail
  • 11.7 6. Update Task
  • 11.8 7. Delete Task
  • 12 Conclusion
  • 12.1 Share this:
  • 12.2 Like this:
  • 12.3 Related

Prerequisites

Before creating this Laravel 8 Sanctum auth project, you will require to have the following tools.

  • PHP >= 7.3
  • MySQL (version > 5)
  • Apache/Nginx Server
  • VS Code Editor
  • Composer
  • Postman/Insomnia

#laravel 8 #laravel sanctum #restful apis #api

Create Laravel 8 Sanctum Authentication For RESTful APIs For Todo App
36.25 GEEK