-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathPersonalAccessTokenResource.php
More file actions
111 lines (91 loc) · 3.41 KB
/
Copy pathPersonalAccessTokenResource.php
File metadata and controls
111 lines (91 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PersonalAccessTokenResource\Pages;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Laravel\Sanctum\PersonalAccessToken;
class PersonalAccessTokenResource extends Resource
{
protected static ?string $model = PersonalAccessToken::class;
protected static ?string $navigationIcon = 'heroicon-o-key';
protected static ?string $navigationLabel = 'API Keys';
protected static ?string $modelLabel = 'API Key';
protected static ?string $pluralModelLabel = 'API Keys';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
->helperText('A descriptive name for this API key'),
Forms\Components\Select::make('tokenable_id')
->label('User')
->options(\App\Models\User::pluck('name', 'id'))
->required()
->searchable(),
Forms\Components\Hidden::make('tokenable_type')
->default(\App\Models\User::class),
Forms\Components\TextInput::make('abilities')
->default('*')
->helperText('Comma-separated list of abilities. Use * for all abilities.'),
Forms\Components\DateTimePicker::make('expires_at')
->label('Expires At')
->nullable()
->helperText('Leave empty for no expiration'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('tokenable.name')
->label('User')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('abilities')
->formatStateUsing(fn ($state) => is_array($state) ? implode(', ', $state) : $state),
Tables\Columns\TextColumn::make('last_used_at')
->dateTime()
->sortable()
->placeholder('Never'),
Tables\Columns\TextColumn::make('expires_at')
->dateTime()
->sortable()
->placeholder('Never'),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
])
->defaultSort('created_at', 'desc');
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPersonalAccessTokens::route('/'),
'create' => Pages\CreatePersonalAccessToken::route('/create'),
];
}
}