Skip to content

Commit

Permalink
Added method for creating API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbjr committed Feb 21, 2016
1 parent 4a70b2d commit f1d8a4f
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/Repositories/ApiKeyRepository.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Chrisbjr\ApiGuard\Repositories;
<?php

namespace Chrisbjr\ApiGuard\Repositories;

use App;
use Eloquent;
Expand All @@ -12,12 +14,19 @@
abstract class ApiKeyRepository extends Eloquent
{

protected $table = 'api_keys';

use SoftDeletes;

protected $table = 'api_keys';

protected $dates = ['deleted_at'];

protected $fillable = [
'user_id',
'key',
'level',
'ignore_limits',
];

/**
* @param $key
* @return ApiKeyRepository
Expand Down Expand Up @@ -50,6 +59,24 @@ public function generateKey()
return $newKey;
}

/**
* Make an ApiKey
*
* @param null $userId
* @param int $level
* @param bool $ignoreLimits
* @return static
*/
public static function make($userId = null, $level = 10, $ignoreLimits = false)
{
return self::create([
'user_id' => $userId,
'key' => self::generateKey(),
'level' => $level,
'ignore_limits' => $ignoreLimits,
]);
}

/**
* Checks whether a key exists in the database or not
*
Expand Down

0 comments on commit f1d8a4f

Please sign in to comment.