Add public API v1 with API key auth, rate limiting, and docs page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
68d01448d2
commit
a583a13da1
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ApiKey extends Model
|
||||
{
|
||||
protected $fillable = ['user_id', 'name', 'key'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public static function generate(User $user, string $name): self
|
||||
{
|
||||
return self::create([
|
||||
'user_id' => $user->id,
|
||||
'name' => $name,
|
||||
'key' => bin2hex(random_bytes(32)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class User extends Authenticatable
|
||||
public function library(): HasMany { return $this->hasMany(UserGame::class); }
|
||||
public function reviews(): HasMany { return $this->hasMany(Review::class); }
|
||||
public function lists(): HasMany { return $this->hasMany(UserList::class); }
|
||||
public function apiKeys(): HasMany { return $this->hasMany(\App\Models\ApiKey::class); }
|
||||
public function activities(): HasMany { return $this->hasMany(Activity::class)->latest(); }
|
||||
public function notifications(): HasMany { return $this->hasMany(Notification::class)->latest('created_at'); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user