Skip to content

Commit

Permalink
Web > User ticket reply işlemi eklendi.
Browse files Browse the repository at this point in the history
  • Loading branch information
berkanumutlu committed Jul 23, 2024
1 parent 72ebabf commit 257bf50
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
42 changes: 39 additions & 3 deletions project/app/Http/Controllers/Web/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;

class UserController extends Controller
Expand Down Expand Up @@ -97,7 +98,7 @@ public function tickets()
->select(['id', 'department', 'receiver_id', 'code', 'subject', 'status', 'created_at', 'deleted_at'])
->get();
$records->map(function ($item) {
$item->url = route('user.tickets.detail', ['code' => $item->code]);
$item->url = route('user.ticket.detail', ['ticket' => $item->code]);
$item->status_text = TicketStatus::from($item->status)->textWithBadge();
$item->created_at_text = format_date(\Carbon\Carbon::parse($item->created_at), 'date-text-with-hour');
});
Expand All @@ -108,12 +109,11 @@ public function show_ticket(Ticket $ticket)
{
$user = Auth::guard('web')->user();
$sender_id = Auth::guard('web')->id();
$sender_id = 2;
if ($ticket->sender_id != $sender_id) {
abort(403);
}
$record = Ticket::query()->where('sender_id', $sender_id)
->with(['receiverId:id,name'])
->with(['receiverId:id,name,avatar'])
->select(['id', 'department', 'receiver_id', 'code', 'subject', 'status', 'created_at', 'deleted_at'])
->first();
if (empty($record)) {
Expand All @@ -136,4 +136,40 @@ public function show_ticket(Ticket $ticket)
$default_logo = voyager_asset('images/logo-icon.png');
return view('web.user.ticket-detail', compact(['record', 'ticket_messages', 'user', 'default_logo']));
}

/**
* @param Request $request
* @param Ticket $ticket
* @return \Illuminate\Http\RedirectResponse
*/
public function reply_ticket(Request $request, Ticket $ticket): \Illuminate\Http\RedirectResponse
{
$validator = Validator::make($request->all(), [
'message' => ['required', 'string', 'min:2']
]);
if ($validator->fails()) {
return redirect()->back()->with([
'message' => $validator->errors()->all(),
'alert-type' => 'danger'
]);
}
try {
Ticket::query()->findOrFail($ticket->id);
$ticket_message = new TicketMessage();
$ticket_message->ticket_id = $ticket->id;
$ticket_message->sender_id = Auth::guard('web')->id();
$ticket_message->message = strip_tags(htmlentities($request->message));
$ticket_message->updated_at = null;
$ticket_message->save();
return redirect()->back()->with([
'message' => 'Message sent successfully.',
'alert-type' => 'success'
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => $e->getMessage(),
'alert-type' => 'danger'
]);
}
}
}
9 changes: 4 additions & 5 deletions project/resources/views/components/web/chat.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<div class="media chat-name align-items-center text-truncate">
<div class="avatar avatar-online d-none d-sm-inline-block mr-3">
@php
$user_avatar = !empty($user->avatar) ? Voyager::image($user->avatar) : $defaultAvatar;
$user_avatar = !empty($record->receiverId->avatar) ? Voyager::image($record->receiverId->avatar) : $defaultAvatar;
@endphp
<img src="{{ $user_avatar }}" alt="{{ $user->name ?? '' }}">
<img src="{{ $user_avatar }}" alt="{{ $record->receiverId?->avatar ?? '' }}">
</div>
<div class="media-body align-self-center ">
<h6 class="text-truncate mb-0">{{ !empty($user->name) ? ucwords($user->name) : '' }}</h6>
<small class="text-muted">{{ $user->email ?? '' }}</small>
<h6 class="text-truncate mb-0">{{ !empty($record->receiverId->name) ? ucwords($record->receiverId->name) : '' }}</h6>
<small class="text-muted">{{ $record->receiverId->email ?? '' }}</small>
</div>
</div>

Expand Down Expand Up @@ -473,7 +473,6 @@
</div>
</main>
</div>
<x-web.errors :errors="$errors"></x-web.errors>

@pushonce("style")
{{--<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">--}}
Expand Down
14 changes: 14 additions & 0 deletions project/resources/views/web/user/ticket-detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
@section("content")
<div class="user-profile-page">
<div class="container container-page">
<x-web.errors :errors="$errors"></x-web.errors>
@if(session('message'))
<div class="w-100">
<div class="alert alert-{{ session('alert-type') }}">
@if(is_array(session('message')))
@foreach(session('message') as $item)
{{ $item }}
@endforeach
@else
{{ session('message') }}
@endif
</div>
</div>
@endif
<x-web.chat
:record="$record"
:defaultAvatar="$default_logo"
Expand Down
2 changes: 1 addition & 1 deletion project/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Route::post('profile/change-password/{user:id}', "update_password")->name('password.edit')->whereNumber('id');
Route::get('tickets', "tickets")->name('tickets');
Route::get('ticket/{ticket:code}', "show_ticket")->name('ticket.detail');
Route::post('ticket/{ticket:code}/reply', "reply")->name('ticket.reply');
Route::post('ticket/{ticket:code}/reply', "reply_ticket")->name('ticket.reply');
});
Route::name('article.')->controller('\App\Http\Controllers\Web\ArticleController')->group(function () {
Route::get('about-us', "show_article_page")->name('about_us');
Expand Down

0 comments on commit 257bf50

Please sign in to comment.