feat: tambah halaman kontak publik dan inbox pesan masuk di dashboard
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages;
|
||||
|
||||
use App\Filament\Resources\ContactMessages\Pages\ListContactMessages;
|
||||
use App\Filament\Resources\ContactMessages\Pages\ViewContactMessage;
|
||||
use App\Models\ContactMessage;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ContactMessageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ContactMessage::class;
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-envelope';
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Konten';
|
||||
protected static ?string $modelLabel = 'Pesan Masuk';
|
||||
|
||||
public static function form(Schema $form): Schema
|
||||
{
|
||||
return $form->schema([]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Nama')->searchable(),
|
||||
TextColumn::make('subject')->label('Subjek')->searchable()->limit(40),
|
||||
TextColumn::make('email')->label('Email'),
|
||||
TextColumn::make('phone')->label('Telepon')->default('-'),
|
||||
TextColumn::make('read_at')->label('Dibaca')
|
||||
->badge()
|
||||
->state(fn ($record) => $record->read_at ? 'Sudah dibaca' : 'Belum dibaca')
|
||||
->color(fn ($record) => $record->read_at ? 'success' : 'warning'),
|
||||
TextColumn::make('created_at')->label('Diterima')->dateTime('d M Y H:i')->sortable(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->recordActions([
|
||||
ViewAction::make()
|
||||
->after(fn ($record) => $record->read_at ?? $record->update(['read_at' => now()])),
|
||||
])
|
||||
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListContactMessages::route('/'),
|
||||
'view' => ViewContactMessage::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages\Pages;
|
||||
|
||||
use App\Filament\Resources\ContactMessages\ContactMessageResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateContactMessage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ContactMessageResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages\Pages;
|
||||
|
||||
use App\Filament\Resources\ContactMessages\ContactMessageResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditContactMessage extends EditRecord
|
||||
{
|
||||
protected static string $resource = ContactMessageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages\Pages;
|
||||
|
||||
use App\Filament\Resources\ContactMessages\ContactMessageResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListContactMessages extends ListRecords
|
||||
{
|
||||
protected static string $resource = ContactMessageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages\Pages;
|
||||
|
||||
use App\Filament\Resources\ContactMessages\ContactMessageResource;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ViewContactMessage extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ContactMessageResource::class;
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
parent::mount($record);
|
||||
$this->record->read_at ?? $this->record->update(['read_at' => now()]);
|
||||
}
|
||||
|
||||
public function infolist(Schema $infolist): Schema
|
||||
{
|
||||
return $infolist->schema([
|
||||
Section::make('Informasi Pengirim')->schema([
|
||||
TextEntry::make('name')->label('Nama'),
|
||||
TextEntry::make('email')->label('Email')->default('-'),
|
||||
TextEntry::make('phone')->label('Telepon')->default('-'),
|
||||
TextEntry::make('created_at')->label('Dikirim')->dateTime('d M Y H:i'),
|
||||
])->columns(2),
|
||||
|
||||
Section::make('Pesan')->schema([
|
||||
TextEntry::make('subject')->label('Subjek'),
|
||||
TextEntry::make('message')->label('Isi Pesan')->columnSpanFull(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages\Schemas;
|
||||
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ContactMessageForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
//
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContactMessages\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ContactMessagesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\ContactMessage;
|
||||
use App\Models\Division;
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
@@ -48,10 +49,23 @@ class PublicController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function blogDetail(Post $post)
|
||||
public function kontak()
|
||||
{
|
||||
abort_if(! $post->published_at || $post->published_at->isFuture(), 404);
|
||||
return view('public.kontak');
|
||||
}
|
||||
|
||||
return view('public.blog-detail', compact('post'));
|
||||
public function kontakStore(\Illuminate\Http\Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'email' => 'nullable|email|max:100',
|
||||
'phone' => 'nullable|string|max:20',
|
||||
'subject' => 'required|string|max:150',
|
||||
'message' => 'required|string|max:2000',
|
||||
]);
|
||||
|
||||
ContactMessage::create($data);
|
||||
|
||||
return back()->with('success', 'Pesan Anda berhasil dikirim. Kami akan segera menghubungi Anda.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContactMessage extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'email', 'phone', 'subject', 'message', 'read_at'];
|
||||
|
||||
protected $casts = ['read_at' => 'datetime'];
|
||||
}
|
||||
Reference in New Issue
Block a user