Category: Laravel, api

in this article we will try to authenticating Laravel API with the new Laravel Sanctum (before Sanctum it was called Laravel Airlock) on Laravel 7.x and Android using Retrofit and RoboPojoGenerator.i’ll make two partpart 1 laravel sanctumpart 2 android authentication Before we start I’ll explain what is Laravel Sanctum, shortly Laravel Sanctum is a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token based APIs.

Install Laravel Let’s install Laravel first with command via terminal or cmd and the terminal or cmd will install current version of Laravel after the install process finish open the folder of our project now we need to install laravel sanctum with this command, write it inside our project folder.composer require laravel/sanctumMake new Databasemake new database named laravel_airlock, and edit .env file inside project folder, only this part and run php artisan migrateMake Users Seeder php artisan make:seeder UsersTableSeeder open the file inside database/seed/UsersTableSeeder.php and edit like image below Add the UsersTableSeeder::class inside file seed/DatabaseSeeder.php and run php artisan db:seedPublish Sanctum Config run this command in terminal or cmd inside project folder after publish config you’ll found new file named sanctum.php inside config folder

Route Partin this part we will try to run the laravel project with postman open file Routes/api.phpedit the file like this and run the project with terminal with php artisan serve open postmanmake new request names login add link http://127.0.0.1:8000/api/loginadd body: with raw and JSON
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners