Skip to content

Commit 04bcdf6

Browse files
committed
added key names - increase key length to 80
1 parent 3cf5b71 commit 04bcdf6

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

database/migrations/2019_01_01_000000_create_api_keys_table.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public function up()
1616
Schema::create('api_keys', function (Blueprint $table) {
1717
$table->bigIncrements('id');
1818
$table->bigInteger('user_id')->index();
19+
$table->string('name', 50);
1920
$table->string('type', 10);
20-
$table->string('api_key', 40)->unique()->nullable()->default(null);
21+
$table->string('api_key', 80)->unique()->nullable()->default(null);
2122
$table->timestamps();
2223
});
2324
}

src/ApiKey.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ApiKey extends Model
1010
protected $with = ['user'];
1111

1212
protected $fillable = [
13-
'user_id', 'type', 'api_key'
13+
'user_id', 'type', 'api_key', 'name'
1414
];
1515

1616
public function user()

src/LaravelApiKeys.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88

99
class LaravelApiKeys
1010
{
11-
public static function create( $apiKeyType = null)
11+
public static function create( $apiKeyType = null, $data = [])
1212
{
1313
if ($apiKeyType === null)
1414
{
1515
$apiKeyType = ApiKeyType::SANDBOX;
1616
}
1717

18+
$name = isset($data['name']) ? $data['name'] : 'Unnamed Key';
19+
dump($name);
20+
1821
return ApiKey::firstOrCreate([
1922
'user_id' => Auth::id(),
2023
'type' => $apiKeyType,
21-
'api_key' => Str::random(40)
24+
'api_key' => Str::random(80),
25+
'name' => $name,
2226
]);
2327
}
2428

0 commit comments

Comments
 (0)