'boolean', ]; public static function booted() { static::creating(function($apiKey){ $apiKey->uuid = Str::uuid('ak'); $apiKey->api_key = bin2hex(random_bytes(32)); }); } public function restaurant() { return $this->belongsTo(Restaurant::class); } /** * Authenticate an API key * Returns the ApiKey model if valid and active, null otherwise */ public static function authenticate($key) { if (empty($key)) { return null; } $apiKey = static::where('api_key', $key) ->where('is_active', 1) ->first(); if ($apiKey) { $apiKey->last_used_at = evavel_now(); $apiKey->save(); } return $apiKey; } }