# Getting Started

### Step 1. Install Laravel <a href="#step-1-install-laravel" id="step-1-install-laravel"></a>

If you have an existing Laravel running project, then you can skip this step. Otherwise, we require to get fresh Laravel application using below command, So open your terminal or command prompt and run  command below:

```
composer create-project --prefer-dist laravel/laravel project_name
```

### Step 2. Install Laravel Passport Package <a href="#step-2-install-laravel-passport-package" id="step-2-install-laravel-passport-package"></a>

To get started, install Passport via the Composer package manager:

```
composer require laravel/passport
```

### Step 3. Run Migration <a href="#step-3-run-migration" id="step-3-run-migration"></a>

Firstly, setup your database with project through `.env` file:

```
DB_DATABASE=DATABASE NAMEDB_USERNAME=USERNAMEDB_PASSWORD=PASSWORD
```

Then do the migrations, Passport migrations will create the tables for your application in database that stores clients and access tokens.

```
php artisan migrate
```

### Step 4. Generate keys <a href="#step-4-generate-keys" id="step-4-generate-keys"></a>

This command will create the encryption keys needed to generate secure access tokens. In addition, the command will create “*personal access*” and “*password grant*” clients which will be used to generate access tokens:

```
php artisan passport:install
```

### Step 5. Passport Config <a href="#step-5-passport-config" id="step-5-passport-config"></a>

Add the `Laravel\Passport\HasApiTokens` trait to your `App\User`model. This trait will provide a few helper methods to your model which allow you to inspect the authenticated user's token and scopes and `HasApiTokens` in `User` class :

```php
<?php
namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use Notifiable, HasApiTokens;
}
```

Next, you should call the `Passport::routes` method within the `boot` method of your `App/Providers/AuthServiceProvider`. This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens. And Add this trait also `use Laravel\Passport\Passport;`

```php
<?php
namespace App\Providers;

use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];
    public function boot()
    {
        $this->registerPolicies();
        Passport::routes();
    }
}
```

Finally, in your `config/auth.php` configuration file, you should set the `driver` option of the `api` authentication guard to `passport`. This will instruct your application to use Passport's `TokenGuard` when authenticating incoming API requests:

```php
'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],
```

**NOTE -**&#x49;n these first five steps, Installation of passport on any Laravel project has been done
