mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-24 03:59:08 -05:00
refactor: use route model binding for staff chat statuses
This commit is contained in:
@@ -17,7 +17,6 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Staff\StoreChatStatusRequest;
|
||||
use App\Http\Requests\Staff\UpdateChatStatusRequest;
|
||||
use App\Models\ChatStatus;
|
||||
use App\Repositories\ChatRepository;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
@@ -25,20 +24,13 @@ use Exception;
|
||||
*/
|
||||
class ChatStatusController extends Controller
|
||||
{
|
||||
/**
|
||||
* ChatController Constructor.
|
||||
*/
|
||||
public function __construct(private readonly ChatRepository $chatRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Chat Management.
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
{
|
||||
return view('Staff.chat.status.index', [
|
||||
'chatstatuses' => $this->chatRepository->statuses(),
|
||||
'chatstatuses' => ChatStatus::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -64,19 +56,19 @@ class ChatStatusController extends Controller
|
||||
/**
|
||||
* Chat Status Edit Form.
|
||||
*/
|
||||
public function edit(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
public function edit(ChatStatus $chatStatus): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
{
|
||||
return view('Staff.chat.status.edit', [
|
||||
'chatstatus' => ChatStatus::findOrFail($id),
|
||||
'chatstatus' => $chatStatus,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update A Chat Status.
|
||||
*/
|
||||
public function update(UpdateChatStatusRequest $request, int $id): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateChatStatusRequest $request, ChatStatus $chatStatus): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
ChatStatus::findOrFail($id)->update($request->validated());
|
||||
$chatStatus->update($request->validated());
|
||||
|
||||
return to_route('staff.statuses.index')
|
||||
->withSuccess('Chat Status Successfully Modified');
|
||||
@@ -87,9 +79,9 @@ class ChatStatusController extends Controller
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function destroy(int $id): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(ChatStatus $chatStatus): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
ChatStatus::findOrFail($id)->delete();
|
||||
$chatStatus->delete();
|
||||
|
||||
return to_route('staff.statuses.index')
|
||||
->withSuccess('Chat Status Successfully Deleted');
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<form
|
||||
class="form"
|
||||
method="POST"
|
||||
action="{{ route('staff.statuses.update', ['id' => $chatstatus->id]) }}"
|
||||
action="{{ route('staff.statuses.update', ['chatStatus' => $chatstatus]) }}"
|
||||
enctype="multipart/form-data"
|
||||
>
|
||||
@csrf
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<tr>
|
||||
<td>{{ $chatstatus->id }}</td>
|
||||
<td>
|
||||
<a href="{{ route('staff.statuses.edit', ['id' => $chatstatus->id]) }}">
|
||||
<a href="{{ route('staff.statuses.edit', ['chatStatus' => $chatstatus]) }}">
|
||||
{{ $chatstatus->name }}
|
||||
</a>
|
||||
</td>
|
||||
@@ -84,7 +84,7 @@
|
||||
<li class="data-table__action">
|
||||
<a
|
||||
class="form__button form__button--text"
|
||||
href="{{ route('staff.statuses.edit', ['id' => $chatstatus->id]) }}"
|
||||
href="{{ route('staff.statuses.edit', ['chatStatus' => $chatstatus]) }}"
|
||||
>
|
||||
{{ __('common.edit') }}
|
||||
</a>
|
||||
@@ -92,7 +92,7 @@
|
||||
<li class="data-table__action">
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ route('staff.statuses.destroy', ['id' => $chatstatus->id]) }}"
|
||||
action="{{ route('staff.statuses.destroy', ['chatStatus' => $chatstatus]) }}"
|
||||
x-data
|
||||
>
|
||||
@csrf
|
||||
|
||||
+7
-7
@@ -718,14 +718,14 @@ Route::middleware('language')->group(function (): void {
|
||||
});
|
||||
|
||||
// Chat Statuses System
|
||||
Route::prefix('chat')->group(function (): void {
|
||||
Route::prefix('chat-statuses')->group(function (): void {
|
||||
Route::name('staff.statuses.')->group(function (): void {
|
||||
Route::get('/statuses', [App\Http\Controllers\Staff\ChatStatusController::class, 'index'])->name('index');
|
||||
Route::get('/statuses/create', [App\Http\Controllers\Staff\ChatStatusController::class, 'create'])->name('create');
|
||||
Route::post('/statuses/store', [App\Http\Controllers\Staff\ChatStatusController::class, 'store'])->name('store');
|
||||
Route::get('/statuses/{id}/edit', [App\Http\Controllers\Staff\ChatStatusController::class, 'edit'])->name('edit');
|
||||
Route::post('/statuses/{id}/update', [App\Http\Controllers\Staff\ChatStatusController::class, 'update'])->name('update');
|
||||
Route::delete('/statuses/{id}/destroy', [App\Http\Controllers\Staff\ChatStatusController::class, 'destroy'])->name('destroy');
|
||||
Route::get('/', [App\Http\Controllers\Staff\ChatStatusController::class, 'index'])->name('index');
|
||||
Route::get('/create', [App\Http\Controllers\Staff\ChatStatusController::class, 'create'])->name('create');
|
||||
Route::post('/', [App\Http\Controllers\Staff\ChatStatusController::class, 'store'])->name('store');
|
||||
Route::get('/{chatStatus}/edit', [App\Http\Controllers\Staff\ChatStatusController::class, 'edit'])->name('edit');
|
||||
Route::post('/{chatStatus}', [App\Http\Controllers\Staff\ChatStatusController::class, 'update'])->name('update');
|
||||
Route::delete('/{chatStatus}', [App\Http\Controllers\Staff\ChatStatusController::class, 'destroy'])->name('destroy');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class ChatStatusControllerTest extends TestCase
|
||||
$user = $this->createStaffUser();
|
||||
$chat_status = ChatStatus::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->delete(route('staff.statuses.destroy', ['id' => $chat_status->id]));
|
||||
$response = $this->actingAs($user)->delete(route('staff.statuses.destroy', ['chatStatus' => $chat_status]));
|
||||
$response->assertRedirect(route('staff.statuses.index'));
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class ChatStatusControllerTest extends TestCase
|
||||
$user = $this->createStaffUser();
|
||||
$chat_status = ChatStatus::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('staff.statuses.update', ['id' => $chat_status->id]), [
|
||||
$response = $this->actingAs($user)->post(route('staff.statuses.update', ['chatStatus' => $chat_status]), [
|
||||
'name' => $chat_status->name,
|
||||
'color' => $chat_status->color,
|
||||
'icon' => $chat_status->icon,
|
||||
|
||||
Reference in New Issue
Block a user