Skip to content

Commit cd5feca

Browse files
committed
Single Support Ticket View
1 parent 3faf133 commit cd5feca

File tree

6 files changed

+173
-11
lines changed

6 files changed

+173
-11
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Account\Support;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\SupportTicket;
7+
use Illuminate\Http\Request;
8+
9+
class TicketController extends Controller
10+
{
11+
public static string $paginationLimit = '10';
12+
13+
public function index()
14+
{
15+
$supportTickets = SupportTicket::whereUserId(auth()->user()->id)
16+
->orderBy('status', 'desc')
17+
->orderBy('created_at', 'desc')
18+
->paginate(static::$paginationLimit);
19+
20+
return view('support.tickets.index', compact('supportTickets'));
21+
}
22+
23+
public function show(SupportTicket $supportTicket)
24+
{
25+
$this->authorize('view', $supportTicket);
26+
27+
$supportTicket->load('user');
28+
29+
return view('support.tickets.show', compact('supportTicket'));
30+
}
31+
}

app/Models/SupportTicket.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ class SupportTicket extends Model
1919
'status',
2020
];
2121

22+
protected static function booted()
23+
{
24+
static::creating(function ($ticket) {
25+
if (is_null($ticket->mask)) {
26+
27+
}
28+
});
29+
}
30+
31+
public function getRouteKeyName(): string
32+
{
33+
return 'mask';
34+
}
35+
2236
public function user(): BelongsTo
2337
{
2438
return $this->belongsTo(User::class);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace App\Policies;
4+
5+
use App\Models\SupportTicket;
6+
use App\Models\User;
7+
use Illuminate\Auth\Access\Response;
8+
9+
class SupportTicketPolicy
10+
{
11+
/**
12+
* Determine whether the user can view any models.
13+
*/
14+
public function viewAny(User $user): bool
15+
{
16+
return false;
17+
}
18+
19+
/**
20+
* Determine whether the user can view the model.
21+
*/
22+
public function view(User $user, SupportTicket $supportTicket): Response
23+
{
24+
return $user->id === $supportTicket->user_id
25+
? Response::allow()
26+
: Response::denyAsNotFound('Ticket not found.');
27+
}
28+
29+
/**
30+
* Determine whether the user can create models.
31+
*/
32+
public function create(User $user): bool
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* Determine whether the user can update the model.
39+
*/
40+
public function update(User $user, SupportTicket $supportTicket): bool
41+
{
42+
return $user->id === $supportTicket->user_id;
43+
}
44+
45+
/**
46+
* Determine whether the user can delete the model.
47+
*/
48+
public function delete(User $user, SupportTicket $supportTicket): bool
49+
{
50+
// Deletion not allowed.
51+
return false;
52+
}
53+
54+
/**
55+
* Determine whether the user can restore the model.
56+
*/
57+
public function restore(User $user, SupportTicket $supportTicket): bool
58+
{
59+
return false;
60+
}
61+
62+
/**
63+
* Determine whether the user can permanently delete the model.
64+
*/
65+
public function forceDelete(User $user, SupportTicket $supportTicket): bool
66+
{
67+
return false;
68+
}
69+
}

resources/views/support/tickets/index.blade.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<x-layout title="Tickets - NativePHP">
2-
{{-- Support Grid Section --}}
32
<section class="mx-auto mt-10 max-w-5xl px-5 md:mt-14">
43
{{-- Header --}}
54
<header class="mb-10 text-center">
@@ -18,8 +17,8 @@
1817
Submit a new request
1918
</a>
2019
</div>
21-
<div class="overflow-x-auto rounded-lg border border-gray-200 dark:border-gray-700 mb-10">
22-
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
20+
<div class="overflow-x-auto rounded-lg border border-gray-200 dark:border-gray-700 mb-10 pb-5">
21+
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700 mb-5">
2322
<thead class="bg-gray-50 dark:bg-gray-800">
2423
<tr>
2524
<th scope="col" class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400">
@@ -37,7 +36,7 @@
3736
</tr>
3837
</thead>
3938
<tbody class="divide-y divide-gray-200 dark:divide-gray-700 bg-white dark:bg-gray-900">
40-
@forelse(auth()->user()->supportTickets as $ticket)
39+
@forelse($supportTickets as $ticket)
4140
<tr>
4241
<td class="whitespace-nowrap px-6 py-4 text-sm font-medium text-gray-900 dark:text-white">
4342
<a href="#" class="text-violet-600">#{{ $ticket->mask }}</a>
@@ -51,7 +50,7 @@
5150
</span>
5251
</td>
5352
<td class="whitespace-nowrap px-6 py-4 text-right text-sm font-medium">
54-
<a href="#" class="rounded-md bg-violet-600 px-3 py-1.5 text-xs font-medium text-white shadow-sm hover:bg-violet-700 dark:bg-violet-700 dark:hover:bg-violet-600 transition duration-200">
53+
<a href="{{ route('support.tickets.show', $ticket) }}" class="rounded-md bg-violet-600 px-3 py-1.5 text-xs font-medium text-white shadow-sm hover:bg-violet-700 dark:bg-violet-700 dark:hover:bg-violet-600 transition duration-200">
5554
View
5655
</a>
5756
</td>
@@ -65,6 +64,10 @@
6564
@endforelse
6665
</tbody>
6766
</table>
67+
68+
<div class="px-5">
69+
{{ $supportTickets->links() }}
70+
</div>
6871
</div>
6972
{{-- Additional Support Information --}}
7073
<div class="mt-20 rounded-xl bg-gradient-to-br from-[#FFF0DC] to-[#E8EEFF] p-8 dark:from-blue-900/10 dark:to-[#4c407f]/25">
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<x-layout-three-columns>
2+
<x-slot name="title">
3+
{{ $supportTicket->subject }}
4+
</x-slot>
5+
6+
<x-slot name="header">
7+
<h1 class="text-2xl font-semibold text-gray-900 dark:text-white">
8+
{{ $supportTicket->subject }}
9+
</h1>
10+
</x-slot>
11+
12+
<section class="mt-6">
13+
<div class="rounded-lg bg-white shadow dark:bg-gray-800">
14+
<div class="p-6">
15+
<h2 class="mb-4 text-xl font-medium">Ticket Details</h2>
16+
<p class="text-gray-700 dark:text-gray-300">
17+
Ticket ID: <strong>#{{ $supportTicket->mask }}</strong><br>
18+
Status: <strong>{{ $supportTicket->status }}</strong><br>
19+
Created At: <strong>{{ $supportTicket->created_at->format('d M Y, H:i') }}</strong><br>
20+
Updated At: <strong>{{ $supportTicket->updated_at->format('d M Y, H:i') }}</strong>
21+
</p>
22+
</div>
23+
</div>
24+
25+
{{-- Ticket Messages --}}
26+
<div class="mt-6 rounded-lg bg-white shadow dark:bg-gray-800">
27+
<div class="p-6">
28+
<h2 class="mb-4 text-xl font-medium">Messages</h2>
29+
@foreach([] as $message)
30+
<div class="mb-4 p-4 border rounded-lg {{ $message->is_from_user ? 'bg-blue-100' : 'bg-green-100' }}">
31+
<p><strong>{{ $message->user->name }}:</strong></p>
32+
<p>{{ $message->content }}</p>
33+
<p class="text-sm text-gray-500">{{ $message->created_at->format('d M Y, H:i') }}</p>
34+
</div>
35+
@endforeach
36+
</div>
37+
</div>
38+
39+
{{-- Additional Support Information --}}
40+
<div class="mt-20 rounded-xl bg-gradient-to-br from-[#FFF0DC] to-[#E8EEFF] p-8 dark:from-blue-900/10 dark:to-[#4c407f]/25">
41+
<h2 class="mb-4 text-2xl font-medium">Need more help?</h2>
42+
<p class="text-lg text-gray-700 dark:text-gray-300">
43+
Check out our <a href="/docs" class="font-medium text-violet-600 hover:text-violet-700 dark:text-violet-400 dark:hover:text-violet-300">documentation</a> for comprehensive guides and tutorials to help you get the most out of NativePHP.
44+
</p>
45+
</div>
46+
</section>
47+
</x-layout-three-columns>

routes/web.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Http\Controllers\Account\AuthController;
4+
use App\Http\Controllers\Account\Support\TicketController;
45
use App\Http\Controllers\ShowDocumentationController;
56
use Illuminate\Support\Facades\Route;
67
use Illuminate\Support\Str;
@@ -68,13 +69,10 @@
6869

6970
Route::prefix('/tickets')
7071
->group(function () {
71-
Route::get('/', function () {
72-
return view('support.tickets.index');
73-
})->name('support.tickets');
72+
Route::get('/', [TicketController::class, 'index'])->name('support.tickets');
7473

75-
Route::get('/{ticketMask}', function ($ticketMask) {
76-
return view('support.tickets.show', ['ticket' => $ticketMask]);
77-
})->name('support.tickets.show');
74+
Route::get('/{supportTicket}', [TicketController::class, 'show'])
75+
->name('support.tickets.show');
7876
});
7977
});
8078

0 commit comments

Comments
 (0)