init
This commit is contained in:
36
app/Models/ApiRequest.php
Normal file
36
app/Models/ApiRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ResponseStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ApiRequest extends Model
|
||||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
protected $fillable = [
|
||||
'website_id',
|
||||
'registration_number',
|
||||
'ip_address',
|
||||
'contact_data',
|
||||
'response_status',
|
||||
'metadata',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'contact_data' => 'array',
|
||||
'metadata' => 'array',
|
||||
'response_status' => ResponseStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function website(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Website::class);
|
||||
}
|
||||
}
|
||||
36
app/Models/Tier.php
Normal file
36
app/Models/Tier.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Tier extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'allowed_fields',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'allowed_fields' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function filterFields(array $data): array
|
||||
{
|
||||
return collect($data)->only($this->allowed_fields ?? [])->all();
|
||||
}
|
||||
|
||||
public function websites(): HasMany
|
||||
{
|
||||
return $this->hasMany(Website::class);
|
||||
}
|
||||
}
|
||||
48
app/Models/User.php
Normal file
48
app/Models/User.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Models/VehicleDataSource.php
Normal file
30
app/Models/VehicleDataSource.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class VehicleDataSource extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'vehicle_record_id',
|
||||
'source_name',
|
||||
'source_url',
|
||||
'last_fetched_at',
|
||||
'cache_expires_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'last_fetched_at' => 'datetime',
|
||||
'cache_expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function vehicleRecord(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(VehicleRecord::class);
|
||||
}
|
||||
}
|
||||
27
app/Models/VehicleRecord.php
Normal file
27
app/Models/VehicleRecord.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class VehicleRecord extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'registration_number',
|
||||
'data',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'data' => AsArrayObject::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function dataSources(): HasMany
|
||||
{
|
||||
return $this->hasMany(VehicleDataSource::class);
|
||||
}
|
||||
}
|
||||
42
app/Models/Website.php
Normal file
42
app/Models/Website.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class Website extends Model
|
||||
{
|
||||
use HasApiTokens, HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'domain',
|
||||
'tier_id',
|
||||
'cache_hit_rate_limit',
|
||||
'external_api_rate_limit',
|
||||
'is_active',
|
||||
'bypass_rate_limit',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'bypass_rate_limit' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function tier(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tier::class);
|
||||
}
|
||||
|
||||
public function apiRequests(): HasMany
|
||||
{
|
||||
return $this->hasMany(ApiRequest::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user