feat: basic log page
This commit is contained in:
parent
faaed8fa1b
commit
e3bb7cb69f
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin IdeHelperLog
|
* @mixin IdeHelperLog
|
||||||
@ -15,4 +16,19 @@ class Log extends Model
|
|||||||
'requested_quote_id',
|
'requested_quote_id',
|
||||||
'content',
|
'content',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function quote(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Quote::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requestedQuote(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(RequestedQuote::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,13 +21,19 @@ class Quote extends Model
|
|||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'quote_id' => $this->id,
|
'quote_id' => $this->id,
|
||||||
'content' => 'Quote requested.'
|
'content' => 'Quote requested.',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'quote',
|
'quote',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function logs(): hasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Log::class);
|
||||||
|
}
|
||||||
|
|
||||||
public static function boot(): void
|
public static function boot(): void
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
@ -35,7 +42,7 @@ class Quote extends Model
|
|||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'quote_id' => $model->id,
|
'quote_id' => $model->id,
|
||||||
'content' => 'Quote created.'
|
'content' => 'Quote created.',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -43,7 +50,7 @@ class Quote extends Model
|
|||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'quote_id' => $model->id,
|
'quote_id' => $model->id,
|
||||||
'content' => 'Quote deleted.'
|
'content' => 'Quote deleted.',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,12 +18,17 @@ class RequestedQuote extends Model
|
|||||||
'user_id',
|
'user_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function logs(): hasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Log::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function approve(): void
|
public function approve(): void
|
||||||
{
|
{
|
||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'requested_quote_id' => $this->id,
|
'requested_quote_id' => $this->id,
|
||||||
'content' => 'Quote approved.'
|
'content' => 'Quote approved.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Quote::create([
|
Quote::create([
|
||||||
@ -37,7 +43,7 @@ class RequestedQuote extends Model
|
|||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'requested_quote_id' => $this->id,
|
'requested_quote_id' => $this->id,
|
||||||
'content' => 'Quote rejected.'
|
'content' => 'Quote rejected.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->delete();
|
$this->delete();
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
@ -61,6 +62,16 @@ class User extends Authenticatable
|
|||||||
'password' => 'hashed',
|
'password' => 'hashed',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function logs(): hasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Log::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fullName(): string
|
||||||
|
{
|
||||||
|
return "{$this->firstname} {$this->lastname}";
|
||||||
|
}
|
||||||
|
|
||||||
public static function boot(): void
|
public static function boot(): void
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
@ -71,7 +82,7 @@ class User extends Authenticatable
|
|||||||
self::created(function ($model) {
|
self::created(function ($model) {
|
||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => $model->id,
|
'user_id' => $model->id,
|
||||||
'content' => 'User created.'
|
'content' => 'User created.',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
9
resources/views/admin/logs.blade.php
Normal file
9
resources/views/admin/logs.blade.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<x-app-layout>
|
||||||
|
<div class="py-12">
|
||||||
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
<div class="p-6 text-nexi-black dark:text-gray-100">
|
||||||
|
<livewire:pages.admin.logs/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
@ -38,12 +38,7 @@
|
|||||||
<x-sidebar-nav :href="route('admin.send')" route="send">Send Quote</x-sidebar-nav>
|
<x-sidebar-nav :href="route('admin.send')" route="send">Send Quote</x-sidebar-nav>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
{{-- TODO: fill with SVG icons to make it pretty --}}
|
<x-sidebar-nav :href="route('admin.logs')" route="admin.log">Logs</x-sidebar-nav>
|
||||||
{{-- <x-sidebar-nav :href="route('a-2')" route="a-2">Second Page</x-sidebar-nav>--}}
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
{{-- TODO: fill with SVG icons to make it pretty --}}
|
|
||||||
{{-- <x-sidebar-nav :href="route('a-3')" route="a-3">Third Page</x-sidebar-nav>--}}
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
67
resources/views/livewire/pages/admin/logs.blade.php
Normal file
67
resources/views/livewire/pages/admin/logs.blade.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Log;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Livewire\Attributes\Layout;
|
||||||
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
|
new #[Layout('layouts.app')] class extends Component
|
||||||
|
{
|
||||||
|
public Collection $logs;
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
$this->getLogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLogs(): void
|
||||||
|
{
|
||||||
|
// TODO: look into pagination for this.
|
||||||
|
$this->logs = Log::with(['user', 'quote', 'requestedQuote'])->get()->sortByDesc('created_at');
|
||||||
|
}
|
||||||
|
}; ?>
|
||||||
|
|
||||||
|
<div class="px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="-mx-4 mt-10 ring-1 ring-gray-300 sm:mx-0 sm:rounded-lg bg-nexi-primary dark:bg-zinc-800 transition-colors duration-300">
|
||||||
|
<table class="min-w-full divide-y divide-gray-300">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col"
|
||||||
|
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-nexi-black dark:text-gray-200 sm:pl-6">
|
||||||
|
User
|
||||||
|
</th>
|
||||||
|
<th scope="col"
|
||||||
|
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||||
|
Logs
|
||||||
|
</th>
|
||||||
|
<th scope="col"
|
||||||
|
class="px-3 py-3.5 text-left text-sm font-semibold text-nexi-black dark:text-gray-200">
|
||||||
|
Type
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($logs as $log)
|
||||||
|
<tr>
|
||||||
|
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm text-nexi-black dark:text-gray-200 sm:pl-0">
|
||||||
|
{{ $log?->user->fullName() ?? 'N/A' }}
|
||||||
|
</td>
|
||||||
|
<td class="whitespace-nowrap px-3 py-4 text-sm text-nexi-black dark:text-gray-200">
|
||||||
|
{{ $log->content }}
|
||||||
|
</td>
|
||||||
|
<td class="whitespace-nowrap px-3 py-4 text-sm text-nexi-black dark:text-gray-200">
|
||||||
|
@if (!empty($log->quote_id))
|
||||||
|
Quote - {{ $log->quote_id }}
|
||||||
|
@elseif (!empty($log->requested_quote_id))
|
||||||
|
Requsted Quote - ID: {{ $log->requested_quote_id }}
|
||||||
|
@else
|
||||||
|
N/A
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ new #[Layout('layouts.app')] class extends Component
|
|||||||
|
|
||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'content' => "Quote sent. {$validated['quote']}"
|
'content' => "Quote sent. {$validated['quote']}",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->quote = '';
|
$this->quote = '';
|
||||||
|
|||||||
@ -42,7 +42,7 @@ new #[Layout('layouts.guest')] class extends Component
|
|||||||
|
|
||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'content' => "Quote sent. {$quote}"
|
'content' => "Quote sent. {$quote}",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->redirect(
|
$this->redirect(
|
||||||
|
|||||||
@ -61,7 +61,7 @@ new #[Layout('layouts.guest')] class extends Component
|
|||||||
|
|
||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'content' => "Quote sent. {$quote}"
|
'content' => "Quote sent. {$quote}",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->redirectRoute('login', navigate: true);
|
$this->redirectRoute('login', navigate: true);
|
||||||
|
|||||||
@ -31,7 +31,7 @@ new class extends Component
|
|||||||
|
|
||||||
Log::create([
|
Log::create([
|
||||||
'user_id' => auth()?->user()?->id,
|
'user_id' => auth()?->user()?->id,
|
||||||
'content' => "Quote sent. {$quote}"
|
'content' => "Quote sent. {$quote}",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reset('current_password', 'password', 'password_confirmation');
|
$this->reset('current_password', 'password', 'password_confirmation');
|
||||||
|
|||||||
@ -29,6 +29,10 @@ Route::view('send', 'admin.send')
|
|||||||
->middleware(['auth'])
|
->middleware(['auth'])
|
||||||
->name('admin.send');
|
->name('admin.send');
|
||||||
|
|
||||||
|
Route::view('/admin/logs', 'admin.logs')
|
||||||
|
->middleware(['auth'])
|
||||||
|
->name('admin.logs');
|
||||||
|
|
||||||
Route::middleware('guest')->group(function () {
|
Route::middleware('guest')->group(function () {
|
||||||
Volt::route('login', 'pages.auth.login')
|
Volt::route('login', 'pages.auth.login')
|
||||||
->name('login');
|
->name('login');
|
||||||
|
|||||||
Reference in New Issue
Block a user