Archived
feat: swap over to spatie logger
This commit is contained in:
1 parent
d3864a69f1
commit
7d94630fd6
22 files changed
+485
-269
No files matched your search
@@ -0,0 +1,106 @@
|
||||
@if ($paginator->hasPages())
|
||||
<nav role="navigation" aria-label="{{ __('Pagination Navigation') }}" class="flex items-center justify-between">
|
||||
<div class="flex justify-between flex-1 sm:hidden">
|
||||
@if ($paginator->onFirstPage())
|
||||
<span class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 rounded-md">
|
||||
{!! __('pagination.previous') !!}
|
||||
</span>
|
||||
@else
|
||||
<a wire:navigate href="{{ $paginator->previousPageUrl() }}" class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 leading-5 rounded-md hover:text-gray-500 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-700 transition ease-in-out duration-150">
|
||||
{!! __('pagination.previous') !!}
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if ($paginator->hasMorePages())
|
||||
<a wire:navigate href="{{ $paginator->nextPageUrl() }}" class="relative inline-flex items-center px-4 py-2 ml-3 text-sm font-medium text-gray-700 bg-white border border-gray-300 leading-5 rounded-md hover:text-gray-500 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-700 transition ease-in-out duration-150">
|
||||
{!! __('pagination.next') !!}
|
||||
</a>
|
||||
@else
|
||||
<span class="relative inline-flex items-center px-4 py-2 ml-3 text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 rounded-md">
|
||||
{!! __('pagination.next') !!}
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-nexi-black dark:text-gray-200 leading-5">
|
||||
{!! __('Showing') !!}
|
||||
@if ($paginator->firstItem())
|
||||
<span class="font-medium">{{ $paginator->firstItem() }}</span>
|
||||
{!! __('to') !!}
|
||||
<span class="font-medium">{{ $paginator->lastItem() }}</span>
|
||||
@else
|
||||
{{ $paginator->count() }}
|
||||
@endif
|
||||
{!! __('of') !!}
|
||||
<span class="font-medium">{{ $paginator->total() }}</span>
|
||||
{!! __('results') !!}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="relative z-0 inline-flex shadow-sm rounded-md">
|
||||
{{-- Previous Page Link --}}
|
||||
@if ($paginator->onFirstPage())
|
||||
<span aria-disabled="true" aria-label="{{ __('pagination.previous') }}">
|
||||
<span class="relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default rounded-l-md leading-5" aria-hidden="true">
|
||||
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
@else
|
||||
<a wire:navigate href="{{ $paginator->previousPageUrl() }}" rel="prev" class="relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-l-md leading-5 hover:text-gray-400 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-500 transition ease-in-out duration-150" aria-label="{{ __('pagination.previous') }}">
|
||||
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
{{-- Pagination Elements --}}
|
||||
@foreach ($elements as $element)
|
||||
{{-- "Three Dots" Separator --}}
|
||||
@if (is_string($element))
|
||||
<span aria-disabled="true">
|
||||
<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-700 bg-white border border-gray-300 cursor-default leading-5">{{ $element }}</span>
|
||||
</span>
|
||||
@endif
|
||||
|
||||
{{-- Array Of Links --}}
|
||||
@if (is_array($element))
|
||||
@foreach ($element as $page => $url)
|
||||
@if ($page == $paginator->currentPage())
|
||||
<span aria-current="page">
|
||||
<span class="relative bg-nexi-red inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-white border border-nexi-red cursor-default leading-5">{{ $page }}</span>
|
||||
</span>
|
||||
@else
|
||||
<a wire:navigate href="{{ $url }}" class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-nexi-black bg-gray-50 border border-gray-300 leading-5 hover:text-gray-500 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-700 transition ease-in-out duration-150" aria-label="{{ __('Go to page :page', ['page' => $page]) }}">
|
||||
{{ $page }}
|
||||
</a>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- Next Page Link --}}
|
||||
@if ($paginator->hasMorePages())
|
||||
<a wire:navigate href="{{ $paginator->nextPageUrl() }}" rel="next" class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-r-md leading-5 hover:text-gray-400 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-500 transition ease-in-out duration-150" aria-label="{{ __('pagination.next') }}">
|
||||
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</a>
|
||||
@else
|
||||
<span aria-disabled="true" aria-label="{{ __('pagination.next') }}">
|
||||
<span class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default rounded-r-md leading-5" aria-hidden="true">
|
||||
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</span>
|
||||
</span>
|
||||
@endif
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@endif
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="sm:fixed sm:top-0 flex flex-row-reverse w-full sm:right-0 p-6 text-right z-10 bg-nexi-primary dark:bg-nexi-primary-dark transition-colors duration-300">
|
||||
<div class="sm:fixed sm:top-0 flex flex-row-reverse w-full border-b border-gray-200 sm:right-0 p-6 text-right z-10 bg-nexi-primary dark:bg-nexi-primary-dark transition-colors duration-300">
|
||||
@auth
|
||||
<div class="pr-6 flex">
|
||||
<a href="{{ url('/dashboard') }}"
|
||||
|
||||
@@ -15,7 +15,7 @@ new class extends Component
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<nav x-data="{ openProfile : false }" class="sticky top-0 z-40 lg:mx-auto lg:max-w-7xl lg:px-8 bg-nexi-primary dark:bg-nexi-primary-dark transition-colors duration-300">
|
||||
<nav x-data="{ openProfile : false }" class="sticky top-0 z-40 lg:mx-auto lg:px-8 bg-nexi-primary dark:bg-nexi-primary-dark transition-colors duration-300">
|
||||
<div class="flex h-16 items-center gap-x-4 border-b border-gray-200 px-4 shadow-sm sm:gap-x-6 sm:px-6 lg:px-0 lg:shadow-none">
|
||||
<button type="button" class="-m-2.5 p-2.5 text-gray-700 lg:hidden" @click="sidebarOpen = true">
|
||||
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RequestedQuote;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Volt\Component;
|
||||
use Livewire\WithPagination;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
new #[Layout('layouts.app')] class extends Component
|
||||
{
|
||||
@@ -11,8 +14,8 @@ new #[Layout('layouts.app')] class extends Component
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
$logs = Log::with(['user', 'loggable'])
|
||||
->orderByDesc('created_at')
|
||||
$logs = Activity::with(['causer', 'subject'])
|
||||
->orderByDesc('id')
|
||||
->paginate(15);
|
||||
|
||||
return [
|
||||
@@ -40,7 +43,7 @@ new #[Layout('layouts.app')] class extends Component
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
Action
|
||||
Event
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||
@@ -56,22 +59,29 @@ new #[Layout('layouts.app')] class extends Component
|
||||
@foreach ($logs as $log)
|
||||
<tr>
|
||||
<td class="relative py-4 px-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log?->user?->full_name ?? 'Anonymous' }}
|
||||
{{ $log?->causer?->full_name ?? 'Anonymous' }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ str_replace('App\Models\\', '', $log->loggable_type) }}
|
||||
{{ str_replace('App\Models\\', '', $log->subject_type) }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->loggable_id }}
|
||||
{{ $log->subject_id }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->action }}
|
||||
{{ \Illuminate\Support\Str::headline($log->event) }}
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->content }}
|
||||
@switch($log->subject_type)
|
||||
@case(Quote::class)
|
||||
@case(RequestedQuote::class)
|
||||
{{ $log?->subject?->quote }}
|
||||
@break
|
||||
@default
|
||||
{{ $log->description }}
|
||||
@endswitch
|
||||
</td>
|
||||
<td class="relative py-4 pr-3 text-sm sm:pl-6 border-t text-nexi-black dark:text-gray-200">
|
||||
{{ $log->ip }}
|
||||
{{ $log->getExtraProperty('ip') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@@ -79,7 +89,7 @@ new #[Layout('layouts.app')] class extends Component
|
||||
</table>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
{{ $logs->links() }}
|
||||
{{ $logs->links('components.paginator') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\Log;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Attributes\Layout;
|
||||
@@ -19,14 +18,9 @@ new #[Layout('layouts.app')] class extends Component
|
||||
// TODO: move this to a helper class so we can reuse code between API and FE
|
||||
$response = Http::post(config('bot.webhook'), ['text' => $validated['quote']]);
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => Log::class,
|
||||
'loggable_id' => null,
|
||||
'action' => LogAction::SEND,
|
||||
'content' => $validated['quote'],
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
activity()
|
||||
->event('send')
|
||||
->log("Manually sent quote: {$validated['quote']}");
|
||||
|
||||
$this->quote = '';
|
||||
}
|
||||
@@ -37,7 +31,7 @@ new #[Layout('layouts.app')] class extends Component
|
||||
<x-text-input
|
||||
wire:model="quote"
|
||||
placeholder="{{ __('What did he say this time?') }}"
|
||||
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
class="block w-full text-nexi-black border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
></x-text-input>
|
||||
|
||||
<x-input-error :messages="$errors->get('quote')" class="mt-2"/>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\Log;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
@@ -42,14 +41,10 @@ new #[Layout('layouts.guest')] class extends Component
|
||||
|
||||
session()->regenerate();
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => User::class,
|
||||
'loggable_id' => auth()->user()->id,
|
||||
'action' => LogAction::ACCESS,
|
||||
'content' => 'User logged in',
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
activity()
|
||||
->performedOn(auth()->user())
|
||||
->event('access')
|
||||
->log('login');
|
||||
|
||||
$this->redirect(
|
||||
session('url.intended', RouteServiceProvider::HOME),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\User;
|
||||
use App\Models\Log;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
@@ -38,17 +37,20 @@ new #[Layout('layouts.guest')] class extends Component
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$this->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($this->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
auth()->user()->update([
|
||||
$status = Password::reset(
|
||||
$this->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function ($user) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($this->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
]);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
@@ -59,16 +61,11 @@ new #[Layout('layouts.guest')] class extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
session()->flash('status', __($status));
|
||||
activity()
|
||||
->event('updated')
|
||||
->log('password reset');
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => User::class,
|
||||
'loggable_id' => auth()?->user()?->id,
|
||||
'action' => LogAction::UPDATE,
|
||||
'content' => 'User reset password via reset',
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
session()->flash('status', __($status));
|
||||
|
||||
$this->redirectRoute('login', navigate: true);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\LogAction;
|
||||
use App\Models\Log;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@@ -27,18 +26,16 @@ new class extends Component
|
||||
throw $e;
|
||||
}
|
||||
|
||||
auth()->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
// We don't want to have a complete log, just something for updating password
|
||||
activity()->withoutLogs(function () {
|
||||
auth()->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
});
|
||||
|
||||
Log::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
'loggable_type' => User::class,
|
||||
'loggable_id' => auth()?->user()?->id,
|
||||
'action' => LogAction::UPDATE,
|
||||
'content' => 'User updated password',
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
activity()
|
||||
->event('updated')
|
||||
->log('password updated');
|
||||
|
||||
$this->reset('current_password', 'password', 'password_confirmation');
|
||||
|
||||
|
||||
Reference in new issue
Block a user