Skip to content

Commit

Permalink
Merge pull request #14 from Innovix-Matrix-Systems/develop
Browse files Browse the repository at this point in the history
Database notification Added
  • Loading branch information
AHS12 authored Oct 14, 2023
2 parents 40b982b + 5530f2c commit b02359d
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 22 deletions.
18 changes: 10 additions & 8 deletions app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public function saveProfile(): void
$user->save();

Notification::make()
->title(__('pages.profile.saved_successfully'))
->title(__('notifications.save.success'))
->success()
->send();
} catch (\Throwable $th) {
//throw $th;
Notification::make()
->title(__('pages.profile.save_failed'))
->title(__('notifications.profile.save.failed'))
->danger()
->send();
}
Expand All @@ -128,13 +128,14 @@ public function updatePassword(): void
$user->save();

Notification::make()
->title(__('pages.profile.password.saved'))
->title(__('notifications.profile.password.save.success'))
->success()
->send();
->send()
->sendToDatabase(Auth::user());
} catch (\Throwable $th) {
//throw $th;
Notification::make()
->title(__('pages.profile.save_failed'))
->title(__('notifications.profile.save.failed'))
->danger()
->send();
}
Expand All @@ -152,15 +153,16 @@ public function updateSettings()
Carbon::setLocale($this->language);

Notification::make()
->title(__('pages.profile.saved_successfully'))
->title(__('notifications.save.success'))
->success()
->send();
->send()
->sendToDatabase(Auth::user());

return redirect('/admin');
} catch (\Throwable $th) {
//throw $th;
Notification::make()
->title(__('pages.profile.save_failed'))
->title(__('notifications.profile.save.failed'))
->danger()
->send();
}
Expand Down
1 change: 0 additions & 1 deletion app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public static function table(Table $table): Table
->deselectRecordsAfterCompletion()
])
])

// ->checkIfRecordIsSelectableUsing(
// fn (User $record): bool => !$record->isSuperAdmin() && Auth::user()->hasPermissionTo('user.delete'),
// ); //performance issue
Expand Down
9 changes: 7 additions & 2 deletions app/Filament/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;

class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

protected function getCreatedNotificationTitle(): ?string
protected function getCreatedNotification(): ?Notification
{
return 'User Created Successfully';
return Notification::make()
->success()
->title(__('notifications.user.created.success'))
->send()
->sendToDatabase(auth()->user());
}
}
23 changes: 18 additions & 5 deletions app/Filament/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Maatwebsite\Excel\Facades\Excel;

Expand All @@ -21,18 +22,30 @@ protected function getHeaderActions(): array
];
}

public function getTabs(): array
{
return [
'all' => Tab::make(),
'active' => Tab::make()
->modifyQueryUsing(fn ($query) => $query->where('is_active', true))
->icon('heroicon-o-check-badge'),
'inactive' => Tab::make()
->modifyQueryUsing(fn ($query) => $query->where('is_active', false))
->icon('heroicon-o-x-circle'),
];
}

private function getExportAction()
{
return Action::make('export')
->label(__('resources.user.export.all'))
->icon('heroicon-o-arrow-down-on-square-stack')
->action('exportAllUsers')
->color('success');
->label(__('resources.user.export.all'))
->icon('heroicon-o-arrow-down-on-square-stack')
->action('exportAllUsers')
->color('success');
}

public function exportAllUsers()
{
return Excel::download(new UsersExport, 'users.csv');
}

}
1 change: 1 addition & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function panel(Panel $panel): Panel
Widgets\AccountWidget::class,
//Widgets\FilamentInfoWidget::class,
])
->databaseNotifications()
->userMenuItems([
MenuItem::make()
->label('Settings')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};
11 changes: 11 additions & 0 deletions lang/bn/notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

return [
'save.success' => 'সফলভাবে সংরক্ষিত হয়েছে',
'profile.save.failed' => 'প্রোফাইল তথ্য আপডেট করতে ব্যর্থ হয়েছে',
'profile.password.save.success' => 'পাসওয়ার্ড সফলভাবে আপডেট করা হয়েছে',
'user.created.success' => 'ব্যবহারকারী সফলভাবে তৈরি করা হয়েছে',

];
3 changes: 0 additions & 3 deletions lang/bn/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
'profile.account_settings' => 'আপনার অ্যাকাউন্টের জন্য সেটিংস',
'profile.password' => 'পাসওয়ার্ড',
'profile.update_password' => 'আপনার পাসওয়ার্ড আপডেট করুন',
'profile.saved_successfully' => 'সফলভাবে সংরক্ষিত হয়েছে',
'profile.save_failed' => 'প্রোফাইল তথ্য আপডেট করতে ব্যর্থ হয়েছে',
'profile.password.saved' => 'পাসওয়ার্ড সফলভাবে আপডেট করা হয়েছে',
'system.settings' => 'অ্যাপ্লিকেশন সিস্টেম সেটিংস',
'system.settings.desc' => 'আপনার সিস্টেম সেটিংস আপডেট করুন',
'system.settings.language' => 'সিস্টেমের ভাষা পরিবর্তন করুন',
Expand Down
11 changes: 11 additions & 0 deletions lang/en/notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

return [
'save.success' => 'Saved successfully',
'profile.save.failed' => 'Failed to update profile information',
'profile.password.save.success' => 'Password Updated Successfully',
'user.created.success' => 'User Created Successfully',

];
3 changes: 0 additions & 3 deletions lang/en/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
'profile.account_settings' => 'settings for your account',
'profile.password' => 'password',
'profile.update_password' => 'update your pasword',
'profile.saved_successfully' => 'saved successfully',
'profile.save_failed' => 'Failed to update profile information',
'profile.password.saved' => 'Password Updated Successfully',
'system.settings' => 'Application System Settings',
'system.settings.desc' => 'Update your system settings',
'system.settings.language' => 'Change System Language',
Expand Down

0 comments on commit b02359d

Please sign in to comment.