Skip to content

Commit

Permalink
Notification (#34)
Browse files Browse the repository at this point in the history
* Send Notification to Admin and SuperAdmin Only

* Fix: notification component alignment

* Fix styling by bot

---------

Co-authored-by: anisAronno <[email protected]>
  • Loading branch information
anisAronno and anisAronno authored Jan 20, 2024
1 parent 513d878 commit a0dc7ad
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ Utilizing the [admintoolkit-html](https://github.com/mostafizurhimself/admintool

6. Run Jobs:

```
php artisan horizon
```

or

```
php artisan queue:work
```
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/NewUserNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function toDatabase($notifiable)
{
return [
'user_id' => $this->user->id,
'message' => 'Registered new user ( '.$this->user->name.' ).',
'message' => 'Registered new user &nbsp; <a target="_blank" class="text-blue-600 font-medium" href="'.route('admin.user.show', $this->user->id).'">'.$this->user->name.'</a>',
];
}
}
6 changes: 5 additions & 1 deletion app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ class UserObserver
*/
public function created(User $user): void
{
Notification::send($user, new NewUserNotification($user));
$admins = User::role(['superadmin', 'admin'])->get();

foreach ($admins as $admin) {
Notification::send($admin, new NewUserNotification($user));
}

$userRole = Role::query()->where('name', 'user');

Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function boot(): void

LogViewer::auth(function ($request)
{
return $request->user()->hasAdministrativeRole();
return $request->user()?->hasAdministrativeRole();
});
}
}
2 changes: 1 addition & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function boot(): void

Gate::define('CanManageMediaContent', function ($user)
{
return $user->hasAdministrativeRole();
return $user?->hasAdministrativeRole();
});
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "anisaronno/laravel-starter",
"type": "project",
"version": "0.2.2",
"version": "0.2.3",
"description": "A perfect laravel starter project for any kind of project.",
"keywords": [
"laravel",
Expand Down
32 changes: 21 additions & 11 deletions resources/views/components/notification.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@ class="text-xs font-medium text-slate-600 hover:text-primary-500 dark:text-slate
</div>

<div class="h-80 w-full" data-simplebar>

<ul>
@foreach (auth()->user()->unreadNotifications as $notification)
@forelse (auth()->user()->unreadNotifications as $notification)
<li class="my-2">
<a href="{{ route('admin.notification', ['id' => $notification->id]) }}"
class="flex cursor-pointer gap-2 px-2 py-2 transition-colors duration-150 hover:bg-gray-200 dark:hover:bg-gray-700 {{ $notification->read_at == null ? 'bg-gray-100 dark:bg-gray-900' : '' }}">
<div
class="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-blue-100 text-blue-500">
<i data-feather="alert-circle" width="20" height="20"></i>
<div
class="flex gap-2 px-2 py-2 transition-colors duration-150 hover:bg-gray-200 dark:hover:bg-gray-700 {{ $notification->read_at == null ? 'bg-gray-100 dark:bg-gray-900' : '' }}">
<div onclick="redirectNotification('{{ route('admin.notification', ['id' => $notification->id]) }}')"
class="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-blue-100 text-blue-500 cursor-pointer">
<i data-feather="check-circle" width="20" height="20"></i>
</div>
<div>
<p class="text-xs text-slate-400">{{ $notification->data['message'] }}</p>
<p class="text-xs text-slate-400 flex justify-center items-center">
{!! $notification->data['message'] !!}
</p>
<p class="mt-1 flex items-center gap-1 text-xs text-slate-400">
<i data-feather="clock" width="1em" height="1em"></i>
<span>{{ $notification->created_at->diffForHumans() }}</span>
</p>
</div>
</a>
</li>
@endforeach
</div>

</li>
@empty
<li class=" text-center my-5 text-red-500">
<p>There have no notifications</p>
</li>
@endforelse
</ul>
</div>

Expand All @@ -56,3 +61,8 @@ class="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-
</div>
</div>
</div>
<script>
function redirectNotification(url) {
window.location.href = url;
}
</script>

0 comments on commit a0dc7ad

Please sign in to comment.