Skip to content

Commit

Permalink
Adding optional configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewSH committed Mar 23, 2018
1 parent bd5ff54 commit 40bb467
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions config/passport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'token' => [
'model' => Laravel\Passport\Token::class,
],
];
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function authCodes()
*/
public function tokens()
{
return $this->hasMany(Token::class, 'client_id');
return $this->hasMany(config('passport.token.model', Laravel\Passport\Token::class), 'client_id');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/HasApiTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function clients()
*/
public function tokens()
{
return $this->hasMany(Token::class, 'user_id')->orderBy('created_at', 'desc');
return $this->hasMany(config('passport.token.model', Laravel\Passport\Token::class), 'user_id')->orderBy('created_at', 'desc');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static function cookie($cookie = null)
*/
public static function actingAs($user, $scopes = [], $guard = 'api')
{
$token = Mockery::mock(Token::class)->shouldIgnoreMissing(false);
$token = Mockery::mock(config('passport.token.model', Laravel\Passport\Token::class))->shouldIgnoreMissing(false);

foreach ($scopes as $scope) {
$token->shouldReceive('can')->with($scope)->andReturn(true);
Expand Down
4 changes: 4 additions & 0 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function boot()
__DIR__.'/../resources/assets/js/components' => base_path('resources/assets/js/components/passport'),
], 'passport-components');

$this->publishes([
__DIR__.'/../config/passport.php' => config_path('passport.php'),
], 'passport-config');

$this->commands([
Console\InstallCommand::class,
Console\ClientCommand::class,
Expand Down
10 changes: 5 additions & 5 deletions src/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TokenRepository
*/
public function create($attributes)
{
return Token::create($attributes);
return config('passport.token.model', Laravel\Passport\Token::class)::create($attributes);
}

/**
Expand All @@ -26,7 +26,7 @@ public function create($attributes)
*/
public function find($id)
{
return Token::find($id);
return config('passport.token.model', Laravel\Passport\Token::class)::find($id);
}

/**
Expand All @@ -38,7 +38,7 @@ public function find($id)
*/
public function findForUser($id, $userId)
{
return Token::where('id', $id)->where('user_id', $userId)->first();
return config('passport.token.model', Laravel\Passport\Token::class)::where('id', $id)->where('user_id', $userId)->first();
}

/**
Expand All @@ -49,7 +49,7 @@ public function findForUser($id, $userId)
*/
public function forUser($userId)
{
return Token::where('user_id', $userId)->get();
return config('passport.token.model', Laravel\Passport\Token::class)::where('user_id', $userId)->get();
}

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ public function save(Token $token)
*/
public function revokeAccessToken($id)
{
return Token::where('id', $id)->update(['revoked' => true]);
return config('passport.token.model', Laravel\Passport\Token::class)::where('id', $id)->update(['revoked' => true]);
}

/**
Expand Down

0 comments on commit 40bb467

Please sign in to comment.