https://github.com/jmrashed/laravel-sanctum-api-authentication-
laravel sanctum api authentication
https://github.com/jmrashed/laravel-sanctum-api-authentication-
Last synced: about 1 month ago
JSON representation
laravel sanctum api authentication
- Host: GitHub
- URL: https://github.com/jmrashed/laravel-sanctum-api-authentication-
- Owner: jmrashed
- Created: 2022-10-01T10:17:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-01T19:19:43.000Z (over 3 years ago)
- Last Synced: 2025-01-07T20:14:39.482Z (over 1 year ago)
- Language: PHP
- Size: 75.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Welcome to the Laravel API Authentication Using LARAVEL SANCTUM- wiki!
## Make REST API AUTHENTICATION in LARAVEL 9 USING LARAVEL SANCTUM
Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token based APIs.
Installation Steps
If you are not using LARAVEL 9 you need to install LARAVEL Sanctum Otherwise you can skip the installation step.
### Step 1
Install via composer
`composer require laravel/sanctum`
### Step 2
Publish the Sanctum Service Provider
`php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"`
### Step 3
Migrate The Database
`php artisan migrate`
## USING SANCTUM IN LARAVEL
User HasApiTokens Trait in App\Models\User
In Order to use Sanctum we need to use HasApiTokens Trait Class in User Model.
User Model should look like.
```php
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
```