init
This commit is contained in:
37
app/DataSourceFields.php
Normal file
37
app/DataSourceFields.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
class DataSourceFields
|
||||
{
|
||||
public const DVLA = [
|
||||
'registrationNumber',
|
||||
'artEndDate',
|
||||
'co2Emissions',
|
||||
'colour',
|
||||
'engineCapacity',
|
||||
'fuelType',
|
||||
'make',
|
||||
'markedForExport',
|
||||
'monthOfFirstRegistration',
|
||||
'motStatus',
|
||||
'revenueWeight',
|
||||
'taxDueDate',
|
||||
'taxStatus',
|
||||
'typeApproval',
|
||||
'wheelplan',
|
||||
'yearOfManufacture',
|
||||
'euroStatus',
|
||||
'realDrivingEmissions',
|
||||
'dateOfLastV5CIssued',
|
||||
];
|
||||
|
||||
public const API2 = [];
|
||||
|
||||
public const API3 = [];
|
||||
|
||||
public static function all(): array
|
||||
{
|
||||
return array_merge(self::DVLA, self::API2, self::API3);
|
||||
}
|
||||
}
|
||||
49
app/Enums/ResponseStatus.php
Normal file
49
app/Enums/ResponseStatus.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasColor;
|
||||
use Filament\Support\Contracts\HasIcon;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum ResponseStatus: string implements HasColor, HasIcon, HasLabel
|
||||
{
|
||||
case CacheHit = 'cache_hit';
|
||||
case ApiFetched = 'api_fetched';
|
||||
case NotFound = 'not_found';
|
||||
case Error = 'error';
|
||||
case ContactSubmitted = 'contact_submitted';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::CacheHit => 'Cache Hit',
|
||||
self::ApiFetched => 'API Fetched',
|
||||
self::NotFound => 'Not Found',
|
||||
self::Error => 'Error',
|
||||
self::ContactSubmitted => 'Contact Submitted',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::CacheHit => 'success',
|
||||
self::ApiFetched => 'info',
|
||||
self::NotFound => 'warning',
|
||||
self::Error => 'danger',
|
||||
self::ContactSubmitted => 'primary',
|
||||
};
|
||||
}
|
||||
|
||||
public function getIcon(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::CacheHit => 'heroicon-m-check-circle',
|
||||
self::ApiFetched => 'heroicon-m-cloud-arrow-down',
|
||||
self::NotFound => 'heroicon-m-magnifying-glass',
|
||||
self::Error => 'heroicon-m-x-circle',
|
||||
self::ContactSubmitted => 'heroicon-m-envelope',
|
||||
};
|
||||
}
|
||||
}
|
||||
50
app/Filament/Resources/ApiRequests/ApiRequestResource.php
Normal file
50
app/Filament/Resources/ApiRequests/ApiRequestResource.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests;
|
||||
|
||||
use App\Filament\Resources\ApiRequests\Pages\CreateApiRequest;
|
||||
use App\Filament\Resources\ApiRequests\Pages\EditApiRequest;
|
||||
use App\Filament\Resources\ApiRequests\Pages\ListApiRequests;
|
||||
use App\Filament\Resources\ApiRequests\Pages\ViewApiRequest;
|
||||
use App\Filament\Resources\ApiRequests\Schemas\ApiRequestForm;
|
||||
use App\Filament\Resources\ApiRequests\Tables\ApiRequestsTable;
|
||||
use App\Models\ApiRequest;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ApiRequestResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ApiRequest::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return ApiRequestForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return ApiRequestsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListApiRequests::route('/'),
|
||||
'create' => CreateApiRequest::route('/create'),
|
||||
'view' => ViewApiRequest::route('/{record}'),
|
||||
'edit' => EditApiRequest::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiRequests\ApiRequestResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateApiRequest extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ApiRequestResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/ApiRequests/Pages/EditApiRequest.php
Normal file
19
app/Filament/Resources/ApiRequests/Pages/EditApiRequest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiRequests\ApiRequestResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditApiRequest extends EditRecord
|
||||
{
|
||||
protected static string $resource = ApiRequestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/ApiRequests/Pages/ListApiRequests.php
Normal file
19
app/Filament/Resources/ApiRequests/Pages/ListApiRequests.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiRequests\ApiRequestResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListApiRequests extends ListRecords
|
||||
{
|
||||
protected static string $resource = ApiRequestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
58
app/Filament/Resources/ApiRequests/Pages/ViewApiRequest.php
Normal file
58
app/Filament/Resources/ApiRequests/Pages/ViewApiRequest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiRequests\ApiRequestResource;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Infolists\Components\KeyValueEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ViewApiRequest extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ApiRequestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
EditAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Request Details')
|
||||
->schema([
|
||||
TextEntry::make('website.name')
|
||||
->label('Website'),
|
||||
TextEntry::make('registration_number')
|
||||
->label('Registration Number')
|
||||
->copyable()
|
||||
->badge()
|
||||
->color('primary'),
|
||||
TextEntry::make('ip_address')
|
||||
->label('IP Address')
|
||||
->copyable(),
|
||||
TextEntry::make('response_status')
|
||||
->label('Response Status')
|
||||
->badge(),
|
||||
TextEntry::make('created_at')
|
||||
->label('Request Time')
|
||||
->dateTime(),
|
||||
])
|
||||
->columns(2),
|
||||
Section::make('Contact Data')
|
||||
->schema([
|
||||
KeyValueEntry::make('contact_data')
|
||||
->label('')
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->collapsed()
|
||||
->collapsible(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests\Schemas;
|
||||
|
||||
use App\Enums\ResponseStatus;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ApiRequestForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('website_id')
|
||||
->relationship('website', 'name')
|
||||
->required(),
|
||||
TextInput::make('registration_number')
|
||||
->required(),
|
||||
TextInput::make('ip_address')
|
||||
->required(),
|
||||
Textarea::make('contact_data')
|
||||
->columnSpanFull(),
|
||||
Select::make('response_status')
|
||||
->options(ResponseStatus::class)
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiRequests\Tables;
|
||||
|
||||
use App\Enums\ResponseStatus;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ApiRequestsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('website.name')
|
||||
->searchable(),
|
||||
TextColumn::make('registration_number')
|
||||
->searchable(),
|
||||
TextColumn::make('ip_address')
|
||||
->searchable(),
|
||||
TextColumn::make('response_status')
|
||||
->badge()
|
||||
->searchable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Tiers/Pages/CreateTier.php
Normal file
11
app/Filament/Resources/Tiers/Pages/CreateTier.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tiers\Pages;
|
||||
|
||||
use App\Filament\Resources\Tiers\TierResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTier extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TierResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Tiers/Pages/EditTier.php
Normal file
19
app/Filament/Resources/Tiers/Pages/EditTier.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tiers\Pages;
|
||||
|
||||
use App\Filament\Resources\Tiers\TierResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTier extends EditRecord
|
||||
{
|
||||
protected static string $resource = TierResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Tiers/Pages/ListTiers.php
Normal file
19
app/Filament/Resources/Tiers/Pages/ListTiers.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tiers\Pages;
|
||||
|
||||
use App\Filament\Resources\Tiers\TierResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTiers extends ListRecords
|
||||
{
|
||||
protected static string $resource = TierResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Filament/Resources/Tiers/Schemas/TierForm.php
Normal file
36
app/Filament/Resources/Tiers/Schemas/TierForm.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tiers\Schemas;
|
||||
|
||||
use App\DataSourceFields;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class TierForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->required(),
|
||||
Textarea::make('description')
|
||||
->columnSpanFull(),
|
||||
CheckboxList::make('allowed_fields')
|
||||
->label('Allowed Fields')
|
||||
->options(array_combine(
|
||||
DataSourceFields::DVLA,
|
||||
DataSourceFields::DVLA
|
||||
))
|
||||
->columns(3)
|
||||
->searchable()
|
||||
->bulkToggleable()
|
||||
->helperText('Select which fields this tier can access.')
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
52
app/Filament/Resources/Tiers/Tables/TiersTable.php
Normal file
52
app/Filament/Resources/Tiers/Tables/TiersTable.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tiers\Tables;
|
||||
|
||||
use App\DataSourceFields;
|
||||
use App\Models\Tier;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class TiersTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
TextColumn::make('slug')
|
||||
->searchable(),
|
||||
TextColumn::make('allowed_fields')
|
||||
->label('Fields')
|
||||
->state(function (Tier $record): string {
|
||||
$total = count(DataSourceFields::DVLA);
|
||||
$selected = count($record->allowed_fields ?? []);
|
||||
|
||||
return "{$selected} of {$total}";
|
||||
}),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
48
app/Filament/Resources/Tiers/TierResource.php
Normal file
48
app/Filament/Resources/Tiers/TierResource.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Tiers;
|
||||
|
||||
use App\Filament\Resources\Tiers\Pages\CreateTier;
|
||||
use App\Filament\Resources\Tiers\Pages\EditTier;
|
||||
use App\Filament\Resources\Tiers\Pages\ListTiers;
|
||||
use App\Filament\Resources\Tiers\Schemas\TierForm;
|
||||
use App\Filament\Resources\Tiers\Tables\TiersTable;
|
||||
use App\Models\Tier;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class TierResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Tier::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return TierForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return TiersTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListTiers::route('/'),
|
||||
'create' => CreateTier::route('/create'),
|
||||
'edit' => EditTier::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleDataSources\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleDataSources\VehicleDataSourceResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateVehicleDataSource extends CreateRecord
|
||||
{
|
||||
protected static string $resource = VehicleDataSourceResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleDataSources\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleDataSources\VehicleDataSourceResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditVehicleDataSource extends EditRecord
|
||||
{
|
||||
protected static string $resource = VehicleDataSourceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleDataSources\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleDataSources\VehicleDataSourceResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListVehicleDataSources extends ListRecords
|
||||
{
|
||||
protected static string $resource = VehicleDataSourceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleDataSources\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class VehicleDataSourceForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('vehicle_record_id')
|
||||
->relationship('vehicleRecord', 'id')
|
||||
->required(),
|
||||
TextInput::make('source_name')
|
||||
->required(),
|
||||
TextInput::make('source_url')
|
||||
->url()
|
||||
->required(),
|
||||
DateTimePicker::make('last_fetched_at')
|
||||
->required(),
|
||||
DateTimePicker::make('cache_expires_at')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleDataSources\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class VehicleDataSourcesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('vehicleRecord.id')
|
||||
->searchable(),
|
||||
TextColumn::make('source_name')
|
||||
->searchable(),
|
||||
TextColumn::make('source_url')
|
||||
->searchable(),
|
||||
TextColumn::make('last_fetched_at')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('cache_expires_at')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleDataSources;
|
||||
|
||||
use App\Filament\Resources\VehicleDataSources\Pages\CreateVehicleDataSource;
|
||||
use App\Filament\Resources\VehicleDataSources\Pages\EditVehicleDataSource;
|
||||
use App\Filament\Resources\VehicleDataSources\Pages\ListVehicleDataSources;
|
||||
use App\Filament\Resources\VehicleDataSources\Schemas\VehicleDataSourceForm;
|
||||
use App\Filament\Resources\VehicleDataSources\Tables\VehicleDataSourcesTable;
|
||||
use App\Models\VehicleDataSource;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class VehicleDataSourceResource extends Resource
|
||||
{
|
||||
protected static ?string $model = VehicleDataSource::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return VehicleDataSourceForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return VehicleDataSourcesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListVehicleDataSources::route('/'),
|
||||
'create' => CreateVehicleDataSource::route('/create'),
|
||||
'edit' => EditVehicleDataSource::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleRecords\VehicleRecordResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateVehicleRecord extends CreateRecord
|
||||
{
|
||||
protected static string $resource = VehicleRecordResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleRecords\VehicleRecordResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditVehicleRecord extends EditRecord
|
||||
{
|
||||
protected static string $resource = VehicleRecordResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleRecords\VehicleRecordResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListVehicleRecords extends ListRecords
|
||||
{
|
||||
protected static string $resource = VehicleRecordResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords\Pages;
|
||||
|
||||
use App\Filament\Resources\VehicleRecords\VehicleRecordResource;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Infolists\Components\KeyValueEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ViewVehicleRecord extends ViewRecord
|
||||
{
|
||||
protected static string $resource = VehicleRecordResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
EditAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(1)
|
||||
->components([
|
||||
Section::make('Vehicle Details')
|
||||
->schema([
|
||||
TextEntry::make('registration_number')
|
||||
->label('Registration Number')
|
||||
->copyable()
|
||||
->badge()
|
||||
->color('primary'),
|
||||
TextEntry::make('created_at')
|
||||
->label('First Cached')
|
||||
->dateTime(),
|
||||
TextEntry::make('updated_at')
|
||||
->label('Last Updated')
|
||||
->dateTime(),
|
||||
])
|
||||
->columns(3),
|
||||
Section::make('Vehicle Data')
|
||||
->schema([
|
||||
KeyValueEntry::make('data')
|
||||
->label('')
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->collapsible(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords\Schemas;
|
||||
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class VehicleRecordForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('registration_number')
|
||||
->required(),
|
||||
Textarea::make('data')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class VehicleRecordsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('registration_number')
|
||||
->searchable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\VehicleRecords;
|
||||
|
||||
use App\Filament\Resources\VehicleRecords\Pages\CreateVehicleRecord;
|
||||
use App\Filament\Resources\VehicleRecords\Pages\EditVehicleRecord;
|
||||
use App\Filament\Resources\VehicleRecords\Pages\ListVehicleRecords;
|
||||
use App\Filament\Resources\VehicleRecords\Pages\ViewVehicleRecord;
|
||||
use App\Filament\Resources\VehicleRecords\Schemas\VehicleRecordForm;
|
||||
use App\Filament\Resources\VehicleRecords\Tables\VehicleRecordsTable;
|
||||
use App\Models\VehicleRecord;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class VehicleRecordResource extends Resource
|
||||
{
|
||||
protected static ?string $model = VehicleRecord::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return VehicleRecordForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return VehicleRecordsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListVehicleRecords::route('/'),
|
||||
'create' => CreateVehicleRecord::route('/create'),
|
||||
'view' => ViewVehicleRecord::route('/{record}'),
|
||||
'edit' => EditVehicleRecord::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Websites/Pages/CreateWebsite.php
Normal file
11
app/Filament/Resources/Websites/Pages/CreateWebsite.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Pages;
|
||||
|
||||
use App\Filament\Resources\Websites\WebsiteResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateWebsite extends CreateRecord
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Websites/Pages/EditWebsite.php
Normal file
19
app/Filament/Resources/Websites/Pages/EditWebsite.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Pages;
|
||||
|
||||
use App\Filament\Resources\Websites\WebsiteResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditWebsite extends EditRecord
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Websites/Pages/ListWebsites.php
Normal file
19
app/Filament/Resources/Websites/Pages/ListWebsites.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Pages;
|
||||
|
||||
use App\Filament\Resources\Websites\WebsiteResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListWebsites extends ListRecords
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\RelationManagers;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TokensRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'tokens';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable()
|
||||
->label('Token Name'),
|
||||
TextColumn::make('last_used_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->placeholder('Never used'),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->label('Created'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Create Token')
|
||||
->modalHeading('Create New API Token')
|
||||
->modalDescription('The token will only be shown once. Make sure to copy it to a secure location.')
|
||||
->using(function (array $data, RelationManager $livewire): void {
|
||||
$token = $livewire->getOwnerRecord()->createToken($data['name']);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Token Created Successfully')
|
||||
->body(Str::markdown("**Your API Token:**\n\n`{$token->plainTextToken}`\n\n⚠️ **Important:** Copy this token now and store it securely. You won't be able to see it again!"))
|
||||
->persistent()
|
||||
->send();
|
||||
})
|
||||
->successNotification(null),
|
||||
])
|
||||
->recordActions([
|
||||
DeleteAction::make()
|
||||
->label('Revoke')
|
||||
->modalHeading('Revoke API Token')
|
||||
->modalDescription('This will permanently revoke this token. Any applications using this token will no longer be able to authenticate.')
|
||||
->successNotificationTitle('Token revoked successfully'),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make()
|
||||
->label('Revoke Selected')
|
||||
->modalHeading('Revoke Selected Tokens')
|
||||
->successNotificationTitle('Tokens revoked successfully'),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('No API Tokens')
|
||||
->emptyStateDescription('Create a token to allow this website to authenticate with the API.')
|
||||
->emptyStateActions([
|
||||
CreateAction::make()
|
||||
->label('Create First Token')
|
||||
->modalHeading('Create New API Token')
|
||||
->modalDescription('The token will only be shown once. Make sure to copy it to a secure location.')
|
||||
->using(function (array $data, RelationManager $livewire): void {
|
||||
$token = $livewire->getOwnerRecord()->createToken($data['name']);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Token Created Successfully')
|
||||
->body(Str::markdown("**Your API Token:**\n\n`{$token->plainTextToken}`\n\n⚠️ **Important:** Copy this token now and store it securely. You won't be able to see it again!"))
|
||||
->persistent()
|
||||
->send();
|
||||
})
|
||||
->successNotification(null),
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Filament/Resources/Websites/Schemas/WebsiteForm.php
Normal file
41
app/Filament/Resources/Websites/Schemas/WebsiteForm.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Schemas;
|
||||
|
||||
use App\Models\Tier;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class WebsiteForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required(),
|
||||
TextInput::make('domain')
|
||||
->required(),
|
||||
Select::make('tier_id')
|
||||
->label('Tier')
|
||||
->relationship('tier', 'name')
|
||||
->required()
|
||||
->searchable()
|
||||
->preload(),
|
||||
TextInput::make('cache_hit_rate_limit')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(100),
|
||||
TextInput::make('external_api_rate_limit')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(10),
|
||||
Toggle::make('is_active')
|
||||
->required(),
|
||||
Toggle::make('bypass_rate_limit')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
56
app/Filament/Resources/Websites/Tables/WebsitesTable.php
Normal file
56
app/Filament/Resources/Websites/Tables/WebsitesTable.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class WebsitesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
TextColumn::make('domain')
|
||||
->searchable(),
|
||||
TextColumn::make('tier.name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('cache_hit_rate_limit')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('external_api_rate_limit')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
IconColumn::make('is_active')
|
||||
->boolean(),
|
||||
IconColumn::make('bypass_rate_limit')
|
||||
->boolean(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
48
app/Filament/Resources/Websites/WebsiteResource.php
Normal file
48
app/Filament/Resources/Websites/WebsiteResource.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites;
|
||||
|
||||
use App\Filament\Resources\Websites\Pages\CreateWebsite;
|
||||
use App\Filament\Resources\Websites\Pages\EditWebsite;
|
||||
use App\Filament\Resources\Websites\Pages\ListWebsites;
|
||||
use App\Filament\Resources\Websites\Schemas\WebsiteForm;
|
||||
use App\Filament\Resources\Websites\Tables\WebsitesTable;
|
||||
use App\Models\Website;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class WebsiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Website::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return WebsiteForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return WebsitesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\TokensRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListWebsites::route('/'),
|
||||
'create' => CreateWebsite::route('/create'),
|
||||
'edit' => EditWebsite::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
43
app/Filament/Widgets/LatestRequestsWidget.php
Normal file
43
app/Filament/Widgets/LatestRequestsWidget.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\ApiRequest;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class LatestRequestsWidget extends TableWidget
|
||||
{
|
||||
protected static ?string $heading = 'Latest Requests';
|
||||
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected int | string | array $columnSpan = 1;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(fn (): Builder => ApiRequest::query()
|
||||
->with('website')
|
||||
->latest()
|
||||
->limit(5)
|
||||
)
|
||||
->columns([
|
||||
TextColumn::make('website.name')
|
||||
->label('Website'),
|
||||
TextColumn::make('registration_number')
|
||||
->label('Reg'),
|
||||
TextColumn::make('response_status')
|
||||
->label('Status')
|
||||
->badge(),
|
||||
TextColumn::make('created_at')
|
||||
->label('When')
|
||||
->since()
|
||||
->alignEnd(),
|
||||
])
|
||||
->searchable(false)
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
40
app/Filament/Widgets/WebsiteRequestsWidget.php
Normal file
40
app/Filament/Widgets/WebsiteRequestsWidget.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Website;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WebsiteRequestsWidget extends TableWidget
|
||||
{
|
||||
protected static ?string $heading = 'Websites by Current Month Requests';
|
||||
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
protected int | string | array $columnSpan = 1;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(fn (): Builder => Website::query()
|
||||
->withCount(['apiRequests' => fn (Builder $query) => $query
|
||||
->whereBetween('created_at', [now()->startOfMonth(), now()->endOfMonth()])
|
||||
])
|
||||
->orderByDesc('api_requests_count')
|
||||
)
|
||||
->columns([
|
||||
TextColumn::make('name'),
|
||||
TextColumn::make('tier.name')
|
||||
->label('Tier'),
|
||||
TextColumn::make('api_requests_count')
|
||||
->label('Requests This Month')
|
||||
->numeric()
|
||||
->alignEnd(),
|
||||
])
|
||||
->searchable(false)
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
34
app/Http/Controllers/Api/ContactEnquiryController.php
Normal file
34
app/Http/Controllers/Api/ContactEnquiryController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Enums\ResponseStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ContactEnquiryRequest;
|
||||
use App\Models\ApiRequest;
|
||||
use App\Models\Website;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ContactEnquiryController extends Controller
|
||||
{
|
||||
public function __invoke(ContactEnquiryRequest $request): JsonResponse
|
||||
{
|
||||
$website = $request->user();
|
||||
$registrationNumber = strtoupper(str_replace(' ', '', $request->validated('registration_number')));
|
||||
|
||||
ApiRequest::create([
|
||||
'website_id' => $website->id,
|
||||
'registration_number' => $registrationNumber,
|
||||
'ip_address' => $request->ip(),
|
||||
'contact_data' => $request->validated('contact_data'),
|
||||
'response_status' => ResponseStatus::ContactSubmitted,
|
||||
'metadata' => [
|
||||
'user_agent' => $request->userAgent(),
|
||||
'referer' => $request->header('referer'),
|
||||
],
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
}
|
||||
195
app/Http/Controllers/Api/VehicleEnquiryController.php
Normal file
195
app/Http/Controllers/Api/VehicleEnquiryController.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Enums\ResponseStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\VehicleEnquiryRequest;
|
||||
use App\Models\ApiRequest;
|
||||
use App\Models\VehicleDataSource;
|
||||
use App\Models\VehicleRecord;
|
||||
use App\Models\Website;
|
||||
use App\Services\DvlaService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class VehicleEnquiryController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DvlaService $dvlaService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(VehicleEnquiryRequest $request): JsonResponse
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$website = $request->user();
|
||||
$registrationNumber = strtoupper(str_replace(' ', '', $request->validated('registration_number')));
|
||||
$contactData = $request->validated('contact_data');
|
||||
|
||||
$vehicleRecord = VehicleRecord::where('registration_number', $registrationNumber)->first();
|
||||
|
||||
if ($vehicleRecord) {
|
||||
$this->logRequest(
|
||||
$website,
|
||||
$registrationNumber,
|
||||
$request->ip(),
|
||||
$contactData,
|
||||
ResponseStatus::CacheHit,
|
||||
$this->buildMetadata($request, $startTime)
|
||||
);
|
||||
$this->incrementCacheHitRateLimit($request);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->filterByTier($vehicleRecord->data, $website),
|
||||
]);
|
||||
}
|
||||
|
||||
if (!$this->checkExternalApiRateLimit($website)) {
|
||||
return response()->json([
|
||||
'message' => 'External API rate limit exceeded',
|
||||
'limit' => $website->external_api_rate_limit,
|
||||
'reset_at' => now()->addHour()->startOfHour()->timestamp,
|
||||
], 429);
|
||||
}
|
||||
|
||||
try {
|
||||
$dvlaData = $this->dvlaService->getVehicleDetails($registrationNumber);
|
||||
|
||||
if (!$dvlaData) {
|
||||
$this->logRequest(
|
||||
$website,
|
||||
$registrationNumber,
|
||||
$request->ip(),
|
||||
$contactData,
|
||||
ResponseStatus::NotFound,
|
||||
$this->buildMetadata($request, $startTime)
|
||||
);
|
||||
$this->incrementExternalApiRateLimit($website);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Vehicle not found',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$vehicleRecord = DB::transaction(function () use ($registrationNumber, $dvlaData) {
|
||||
$vehicle = VehicleRecord::create([
|
||||
'registration_number' => $registrationNumber,
|
||||
'data' => $dvlaData,
|
||||
]);
|
||||
|
||||
VehicleDataSource::create([
|
||||
'vehicle_record_id' => $vehicle->id,
|
||||
'source_name' => 'dvla',
|
||||
'source_url' => DvlaService::class.'::API_URL',
|
||||
'last_fetched_at' => now(),
|
||||
'cache_expires_at' => now()->addMonths(6),
|
||||
]);
|
||||
|
||||
return $vehicle;
|
||||
});
|
||||
|
||||
$this->logRequest(
|
||||
$website,
|
||||
$registrationNumber,
|
||||
$request->ip(),
|
||||
$contactData,
|
||||
ResponseStatus::ApiFetched,
|
||||
$this->buildMetadata($request, $startTime)
|
||||
);
|
||||
$this->incrementExternalApiRateLimit($website);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->filterByTier($vehicleRecord->data, $website),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->logRequest(
|
||||
$website,
|
||||
$registrationNumber,
|
||||
$request->ip(),
|
||||
$contactData,
|
||||
ResponseStatus::Error,
|
||||
$this->buildMetadata($request, $startTime, $e->getMessage())
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Failed to fetch vehicle details',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function logRequest(Website $website, string $registrationNumber, string $ipAddress, ?array $contactData, ResponseStatus $status, array $metadata = []): void
|
||||
{
|
||||
ApiRequest::create([
|
||||
'website_id' => $website->id,
|
||||
'registration_number' => $registrationNumber,
|
||||
'ip_address' => $ipAddress,
|
||||
'contact_data' => $contactData,
|
||||
'response_status' => $status,
|
||||
'metadata' => $metadata,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function buildMetadata($request, float $startTime, ?string $errorMessage = null): array
|
||||
{
|
||||
$responseTime = round((microtime(true) - $startTime) * 1000, 2);
|
||||
|
||||
$metadata = [
|
||||
'user_agent' => $request->userAgent(),
|
||||
'response_time_ms' => $responseTime,
|
||||
'referer' => $request->header('referer'),
|
||||
'accept' => $request->header('accept'),
|
||||
];
|
||||
|
||||
if ($errorMessage) {
|
||||
$metadata['error_message'] = $errorMessage;
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
private function incrementCacheHitRateLimit($request): void
|
||||
{
|
||||
$cacheKey = $request->attributes->get('rate_limit_key');
|
||||
|
||||
if ($cacheKey) {
|
||||
$value = Cache::increment($cacheKey);
|
||||
Cache::put($cacheKey, $value, 3600);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkExternalApiRateLimit(Website $website): bool
|
||||
{
|
||||
if (app()->environment('local') || $website->bypass_rate_limit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$hour = now()->format('Y-m-d-H');
|
||||
$cacheKey = "rate_limit:website:{$website->id}:external_api:{$hour}";
|
||||
$attempts = Cache::get($cacheKey, 0);
|
||||
|
||||
return $attempts < $website->external_api_rate_limit;
|
||||
}
|
||||
|
||||
private function incrementExternalApiRateLimit(Website $website): void
|
||||
{
|
||||
if (app()->environment('local') || $website->bypass_rate_limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hour = now()->format('Y-m-d-H');
|
||||
$cacheKey = "rate_limit:website:{$website->id}:external_api:{$hour}";
|
||||
|
||||
$value = Cache::increment($cacheKey);
|
||||
Cache::put($cacheKey, $value, 3600);
|
||||
}
|
||||
|
||||
private function filterByTier(mixed $data, Website $website): array
|
||||
{
|
||||
return $website->tier->filterFields((array) $data);
|
||||
}
|
||||
}
|
||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
69
app/Http/Middleware/RateLimitApiRequests.php
Normal file
69
app/Http/Middleware/RateLimitApiRequests.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Website;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RateLimitApiRequests
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$website = $request->user();
|
||||
|
||||
if (!$website instanceof Website) {
|
||||
return response()->json(['message' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
if (!$website->is_active) {
|
||||
return response()->json(['message' => 'Account inactive'], 403);
|
||||
}
|
||||
|
||||
if (app()->environment('local') || $website->bypass_rate_limit) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (!$this->originMatchesDomain($request, $website)) {
|
||||
return response()->json(['message' => 'Forbidden'], 403);
|
||||
}
|
||||
|
||||
$hour = now()->format('Y-m-d-H');
|
||||
$cacheKey = "rate_limit:website:{$website->id}:cache_hits:{$hour}";
|
||||
$attempts = Cache::get($cacheKey, 0);
|
||||
|
||||
if ($attempts >= $website->cache_hit_rate_limit) {
|
||||
return response()->json([
|
||||
'message' => 'Rate limit exceeded',
|
||||
'limit' => $website->cache_hit_rate_limit,
|
||||
'reset_at' => now()->addHour()->startOfHour()->timestamp,
|
||||
], 429);
|
||||
}
|
||||
|
||||
$request->attributes->set('rate_limit_key', $cacheKey);
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
|
||||
$response->headers->set('X-RateLimit-Limit', $website->cache_hit_rate_limit);
|
||||
$response->headers->set('X-RateLimit-Remaining', max(0, $website->cache_hit_rate_limit - $attempts - 1));
|
||||
$response->headers->set('X-RateLimit-Reset', now()->addHour()->startOfHour()->timestamp);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function originMatchesDomain(Request $request, Website $website): bool
|
||||
{
|
||||
$origin = $request->header('Origin') ?? $request->header('Referer');
|
||||
|
||||
if (!$origin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$host = parse_url($origin, PHP_URL_HOST);
|
||||
|
||||
return $host === $website->domain;
|
||||
}
|
||||
}
|
||||
40
app/Http/Requests/ContactEnquiryRequest.php
Normal file
40
app/Http/Requests/ContactEnquiryRequest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ContactEnquiryRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_number' => ['required', 'string', 'max:8', 'regex:/^(?=.*\d)[A-Za-z0-9 ]+$/'],
|
||||
'contact_data' => ['required', 'array'],
|
||||
'contact_data.name' => ['nullable', 'string', 'max:255'],
|
||||
'contact_data.email' => ['required_without:contact_data.phone', 'nullable', 'email', 'max:255'],
|
||||
'contact_data.phone' => ['required_without:contact_data.email', 'nullable', 'string', 'max:50'],
|
||||
'contact_data.address' => ['nullable', 'string', 'max:500'],
|
||||
'contact_data.message' => ['nullable', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'registration_number.required' => 'Vehicle registration number is required',
|
||||
'registration_number.max' => 'Vehicle registration number must not exceed 8 characters',
|
||||
'registration_number.regex' => 'Invalid registration number format',
|
||||
'contact_data.required' => 'Contact data is required',
|
||||
'contact_data.array' => 'Contact data must be a valid object',
|
||||
'contact_data.email.required_without' => 'Please provide at least an email address or phone number',
|
||||
'contact_data.email.email' => 'Please provide a valid email address',
|
||||
'contact_data.phone.required_without' => 'Please provide at least a phone number or email address',
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Http/Requests/VehicleEnquiryRequest.php
Normal file
36
app/Http/Requests/VehicleEnquiryRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class VehicleEnquiryRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_number' => ['required', 'string', 'max:8', 'regex:/^(?=.*\d)[A-Za-z0-9 ]+$/'],
|
||||
'contact_data' => ['nullable', 'array'],
|
||||
'contact_data.name' => ['nullable', 'string', 'max:255'],
|
||||
'contact_data.email' => ['nullable', 'email', 'max:255'],
|
||||
'contact_data.phone' => ['nullable', 'string', 'max:50'],
|
||||
'contact_data.address' => ['nullable', 'string', 'max:500'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'registration_number.required' => 'Vehicle registration number is required',
|
||||
'registration_number.max' => 'Vehicle registration number must not exceed 8 characters',
|
||||
'registration_number.regex' => 'Invalid registration number format',
|
||||
'contact_data.array' => 'Contact data must be a valid object',
|
||||
'contact_data.email.email' => 'Please provide a valid email address',
|
||||
];
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
25
app/Providers/AppServiceProvider.php
Normal file
25
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(\App\Services\DvlaService::class, function (): \App\Services\DvlaService {
|
||||
return new \App\Services\DvlaService(
|
||||
apiKey: config('services.dvla.api_key')
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
54
app/Providers/Filament/AdminPanelProvider.php
Normal file
54
app/Providers/Filament/AdminPanelProvider.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\AuthenticateSession;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
use Filament\Pages\Dashboard;
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
->default()
|
||||
->id('admin')
|
||||
->path('admin')
|
||||
->login()
|
||||
->colors([
|
||||
'primary' => Color::Amber,
|
||||
])
|
||||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
||||
->pages([
|
||||
Dashboard::class,
|
||||
])
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
|
||||
->widgets([])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
AuthenticateSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
PreventRequestForgery::class,
|
||||
SubstituteBindings::class,
|
||||
DisableBladeIconComponents::class,
|
||||
DispatchServingFilamentEvent::class,
|
||||
])
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Services/DvlaService.php
Normal file
41
app/Services/DvlaService.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class DvlaService
|
||||
{
|
||||
private const API_URL = 'https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles';
|
||||
|
||||
public function __construct(
|
||||
private readonly string $apiKey
|
||||
) {
|
||||
}
|
||||
|
||||
public function getVehicleDetails(string $registrationNumber): ?array
|
||||
{
|
||||
$response = $this->client()->post(self::API_URL, [
|
||||
'registrationNumber' => $registrationNumber,
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
if ($response->status() === 404) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$response->throw();
|
||||
}
|
||||
|
||||
private function client(): PendingRequest
|
||||
{
|
||||
return Http::withHeaders([
|
||||
'x-api-key' => $this->apiKey,
|
||||
'Content-Type' => 'application/json',
|
||||
])->timeout(30);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user