An open API service indexing awesome lists of open source software.

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

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',
];
}
```