From fe5ff7e51add129bb8c06a2f30b6a2ff857a5961 Mon Sep 17 00:00:00 2001 From: jeremy-portable Date: Wed, 13 Nov 2024 10:11:16 +0800 Subject: [PATCH] Show who made the entry when it's for logged in users only --- resources/views/tables/columns/created_by.blade.php | 9 +++++++++ src/Filament/Resources/FormEntryResource.php | 6 ++++++ src/Models/FormEntry.php | 5 +++++ 3 files changed, 20 insertions(+) create mode 100644 resources/views/tables/columns/created_by.blade.php diff --git a/resources/views/tables/columns/created_by.blade.php b/resources/views/tables/columns/created_by.blade.php new file mode 100644 index 00000000..e912b757 --- /dev/null +++ b/resources/views/tables/columns/created_by.blade.php @@ -0,0 +1,9 @@ +
+
+
+ + {{ $getRecord()->User?->name }} + +
+
+
diff --git a/src/Filament/Resources/FormEntryResource.php b/src/Filament/Resources/FormEntryResource.php index acbb6c77..82ee8c78 100644 --- a/src/Filament/Resources/FormEntryResource.php +++ b/src/Filament/Resources/FormEntryResource.php @@ -96,6 +96,12 @@ public static function getColumns(ModelsForm $form): array ->words(10); } + if ($form->only_for_logged_in) { + // show user who created it + $columns[] = Tables\Columns\ViewColumn::make('') + ->label('Submitted By') + ->view('fila-cms::tables.columns.created_by'); + } $columns[] = Tables\Columns\ViewColumn::make('created_at') ->label('Submitted Time') diff --git a/src/Models/FormEntry.php b/src/Models/FormEntry.php index 1bffd0c9..0cd873da 100644 --- a/src/Models/FormEntry.php +++ b/src/Models/FormEntry.php @@ -38,6 +38,11 @@ public function form() return $this->belongsTo(Form::class); } + public function user() + { + return $this->belongsTo(config('auth.providers.users.model')); + } + public function displayHtml(): Attribute { return new Attribute(function () {