Tester
Tester

Reputation: 808

Laravel managing Personal Access Tokens

I'm following Laravel documentation to "Managing Personal Access Tokens"

I created a TestController try to create a personal access token.

  public function getToken()
    {

      $user = \App\User::find(1);
      // Creating a token without scopes...
      $token = $user->createToken('3page')->accessToken;
      dd($token);

    }

I can get the $user but get error when createToken

{
    "message": "Trying to get property 'id' of non-object",
    "exception": "ErrorException",
    "file": "/home/vagrant/code/test/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
    "line": 98,
    "trace": [
        {
            "file": "/home/vagrant/code/test/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
            "line": 98,
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },

Please advice!

Upvotes: 0

Views: 1476

Answers (1)

Stefano
Stefano

Reputation: 178

Did you run php artisan passport:client --personal command?

You have to set the --personal flag in order to use your code.

Reference: https://laravel.com/docs/6.x/passport#creating-a-personal-access-client

Upvotes: 1

Related Questions