소스 검색

add employees table

3.x
Andrew Wallo 2 년 전
부모
커밋
8701ebb508

+ 1
- 1
app/Filament/Pages/Companies.php 파일 보기

@@ -24,7 +24,7 @@ class Companies extends Page
24 24
     protected function getHeaderWidgets(): array
25 25
     {
26 26
         return [
27
-            \App\Filament\Pages\Widgets\Companies::class,
27
+            Widgets\Companies::class,
28 28
         ];
29 29
     }
30 30
 }

+ 30
- 0
app/Filament/Pages/Employees.php 파일 보기

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+namespace App\Filament\Pages;
4
+
5
+use Filament\Pages\Page;
6
+use Illuminate\Support\Facades\Auth;
7
+
8
+class Employees extends Page
9
+{
10
+    protected static ?string $navigationIcon = 'heroicon-o-users';
11
+
12
+    protected static string $view = 'filament.pages.employees';
13
+
14
+    protected static function shouldRegisterNavigation(): bool
15
+    {
16
+        return Auth::user()->currentCompany->name === 'ERPSAAS';
17
+    }
18
+
19
+    public function mount(): void
20
+    {
21
+        abort_unless(Auth::user()->currentCompany->name === 'ERPSAAS', 403);
22
+    }
23
+
24
+    protected function getHeaderWidgets(): array
25
+    {
26
+        return [
27
+            Widgets\Employees::class,
28
+        ];
29
+    }
30
+}

+ 1
- 1
app/Filament/Pages/Users.php 파일 보기

@@ -24,7 +24,7 @@ class Users extends Page
24 24
     protected function getHeaderWidgets(): array
25 25
     {
26 26
         return [
27
-            \App\Filament\Pages\Widgets\Users::class,
27
+            Widgets\Users::class,
28 28
         ];
29 29
     }
30 30
 }

+ 3
- 1
app/Filament/Pages/Widgets/Companies.php 파일 보기

@@ -49,11 +49,13 @@ class Companies extends PageWidget
49 49
                 ->view('filament.components.companies.avatar-column')
50 50
                 ->label('Owner')
51 51
                 ->sortable()
52
+                ->searchable()
52 53
                 ->grow(false),
53 54
             Tables\Columns\TextColumn::make('name')
54 55
                 ->weight('semibold')
55 56
                 ->label('Company')
56
-                ->sortable(),
57
+                ->sortable()
58
+                ->searchable(),
57 59
             Tables\Columns\TextColumn::make('users_count')
58 60
                 ->label('Employees')
59 61
                 ->weight('semibold')

+ 70
- 0
app/Filament/Pages/Widgets/Employees.php 파일 보기

@@ -0,0 +1,70 @@
1
+<?php
2
+
3
+namespace App\Filament\Pages\Widgets;
4
+
5
+use App\Models\User;
6
+use Closure;
7
+use Exception;
8
+use Filament\Tables;
9
+use Filament\Widgets\TableWidget as PageWidget;
10
+use Illuminate\Contracts\Support\Htmlable;
11
+use Illuminate\Database\Eloquent\Builder;
12
+use Illuminate\Database\Eloquent\Relations\Relation;
13
+
14
+class Employees extends PageWidget
15
+{
16
+    protected int|string|array $columnSpan = [
17
+        'md' => 2,
18
+        'xl' => 3,
19
+    ];
20
+
21
+    protected function getTableQuery(): Builder|Relation
22
+    {
23
+        return User::whereHas('employeeships');
24
+    }
25
+
26
+    protected function getTableHeading(): string|Htmlable|Closure|null
27
+    {
28
+        return null;
29
+    }
30
+
31
+    /**
32
+     * @throws Exception
33
+     */
34
+    protected function getTableFilters(): array
35
+    {
36
+        return [
37
+            Tables\Filters\SelectFilter::make('name')
38
+                ->label('Company')
39
+                ->relationship('companies', 'name', static fn (Builder $query) => $query->whereHas('users')),
40
+        ];
41
+    }
42
+
43
+    protected function getTableColumns(): array
44
+    {
45
+        return [
46
+            Tables\Columns\ViewColumn::make('name')
47
+                ->view('filament.components.users.avatar-column')
48
+                ->label('Name')
49
+                ->sortable()
50
+                ->searchable()
51
+                ->grow(false),
52
+            Tables\Columns\TextColumn::make('companies.name')
53
+                ->label('Company')
54
+                ->sortable()
55
+                ->searchable()
56
+                ->weight('semibold'),
57
+            Tables\Columns\BadgeColumn::make('employeeships.role')
58
+                ->label('Role')
59
+                ->icons([
60
+                    'heroicon-o-shield-check' => 'admin',
61
+                    'heroicon-o-pencil' => 'editor',
62
+                ])
63
+                ->colors([
64
+                    'primary' => 'admin',
65
+                    'warning' => 'editor',
66
+                ])
67
+                ->sortable(),
68
+        ];
69
+    }
70
+}

+ 1
- 0
app/Filament/Pages/Widgets/Users.php 파일 보기

@@ -34,6 +34,7 @@ class Users extends PageWidget
34 34
                 ->view('filament.components.users.avatar-column')
35 35
                 ->label('Name')
36 36
                 ->sortable()
37
+                ->searchable()
37 38
                 ->grow(false),
38 39
             Tables\Columns\TextColumn::make('owned_companies')
39 40
                 ->label('Companies')

+ 6
- 0
app/Models/User.php 파일 보기

@@ -5,6 +5,7 @@ namespace App\Models;
5 5
 use Filament\Models\Contracts\FilamentUser;
6 6
 use Filament\Models\Contracts\HasAvatar;
7 7
 use Illuminate\Database\Eloquent\Factories\HasFactory;
8
+use Illuminate\Database\Eloquent\Relations\HasMany;
8 9
 use Illuminate\Foundation\Auth\User as Authenticatable;
9 10
 use Illuminate\Notifications\Notifiable;
10 11
 use Laravel\Fortify\TwoFactorAuthenticatable;
@@ -35,6 +36,11 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
35 36
         return $this->profile_photo_url;
36 37
     }
37 38
 
39
+    public function employeeships(): HasMany
40
+    {
41
+        return $this->hasMany(Employeeship::class);
42
+    }
43
+
38 44
     /**
39 45
      * The attributes that are mass assignable.
40 46
      *

+ 3
- 0
resources/views/filament/pages/employees.blade.php 파일 보기

@@ -0,0 +1,3 @@
1
+<x-filament::page>
2
+
3
+</x-filament::page>

Loading…
취소
저장