add methods edit, delete, update for reception screen
Tests & Lint & Deploy to Railway / build (20.x, 8.2) (push) Successful in 1m57s Details
Tests & Lint & Deploy to Railway / deploy (8.1) (push) Failing after 1m15s Details

This commit is contained in:
aslan 2024-01-25 10:22:23 +03:00
parent 7d0c12a086
commit a7b2fd58d5
4 changed files with 47 additions and 40 deletions

View File

@ -14,8 +14,8 @@ class ReceptionScreenController extends Controller
{ {
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{ {
$onlineDocuments = ReceptionScreen::all()->sortBy('position'); $receptionScreens = ReceptionScreen::all()->sortBy('position');
return view('admin-reception-screen.index', compact('onlineDocuments')); return view('admin-reception-screen.index', compact('receptionScreens'));
} }
public function create(): View public function create(): View
@ -29,10 +29,6 @@ class ReceptionScreenController extends Controller
public function store(StoreReceptionScreenRequest $request) public function store(StoreReceptionScreenRequest $request)
{ {
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
$validated = $request->validated(); $validated = $request->validated();
$receptionScreen = new ReceptionScreen(); $receptionScreen = new ReceptionScreen();
$receptionScreen->name = $validated['name']; $receptionScreen->name = $validated['name'];
@ -41,25 +37,35 @@ class ReceptionScreenController extends Controller
return redirect()->route('admin-reception-screen.index'); return redirect()->route('admin-reception-screen.index');
} }
public function edit(ReceptionScreen $currentOnlineDocument) public function edit($id)
{ {
if (Auth::guest()) { $receptionScreen = new ReceptionScreen();
abort(403, 'Вы не авторизованы!'); $currentReceptionScreen = $receptionScreen->find($id);
$receptionScreens = $receptionScreen->all()->sortBy('position');
return view('admin-reception-screen.edit', compact('currentReceptionScreen', 'receptionScreens'));
}
public function update(UpdateReceptionScreenRequest $request, $id)
{
$validated = $request->validated();
$receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id);
$currentReceptionScreen->name = $validated['name'];
$currentReceptionScreen->position = $validated['position'];
$currentReceptionScreen->save();
return redirect()->route('admin-reception-screen.index');
}
public function destroy($id)
{
$receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id);
if ($currentReceptionScreen->files()->exists()) {
return back();
} }
$onlineDocuments = ReceptionScreen::all()->sortBy('position'); $currentReceptionScreen->delete();
return view('admin-reception-screen.edit', compact('currentOnlineDocument', 'onlineDocuments'));
}
public function update(UpdateReceptionScreenRequest $request, ReceptionScreen $doceumentsOnline) return redirect()->route('admin-reception-screen.index');
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(ReceptionScreen $doceumentsOnline)
{
//
} }
} }

View File

@ -46,10 +46,10 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($onlineDocuments as $onlineDocument) @foreach($receptionScreens as $receptionScreen)
<tr> <tr>
<th scope="row">{{ $onlineDocument->position }}</th> <th scope="row">{{ $receptionScreen->position }}</th>
<td>{{ $onlineDocument->name }}</td> <td>{{ $receptionScreen->name }}</td>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>

View File

@ -5,13 +5,14 @@
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1 class=""> Изменить пункт Экрана приема</h1> <h1 class=""> Изменить пункт Экрана приема</h1>
{{ Form::open(['url' => route('admin-reception-screen.update', $currentOnlineDocument), 'method' => 'PATCH', 'class' => '']) }}
{{ Form::open(['url' => route('admin-reception-screen.update', $currentReceptionScreen), 'method' => 'PATCH', 'class' => '']) }}
<div class="col"> <div class="col">
<div> <div>
{{ Form::label('position', 'Позиция') }} {{ Form::label('position', 'Позиция') }}
</div> </div>
<div class="mt-2"> <div class="mt-2">
{{ Form::text('position', $currentOnlineDocument->position, ['class' => 'form-control']) }} {{ Form::text('position', $currentReceptionScreen->position, ['class' => 'form-control']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
@ -23,7 +24,7 @@
{{ Form::label('name', 'Название') }} {{ Form::label('name', 'Название') }}
</div> </div>
<div class="mt-2"> <div class="mt-2">
{{ Form::text('name', '', ['class' => 'form-control']) }} {{ Form::text('name', $currentReceptionScreen->name, ['class' => 'form-control']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
@ -32,7 +33,7 @@
</div> </div>
<div class="mt-4"> <div class="mt-4">
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }} {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div> </div>
</div> </div>
{{ Form::close() }} {{ Form::close() }}
@ -46,10 +47,10 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($onlineDocuments as $onlineDocument) @foreach($receptionScreens as $receptionScreen)
<tr> <tr>
<th scope="row">{{ $onlineDocument->position }}</th> <th scope="row">{{ $receptionScreen->position }}</th>
<td>{{ $onlineDocument->name }}</td> <td>{{ $receptionScreen->name }}</td>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>

View File

@ -15,17 +15,17 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($onlineDocuments as $onlineDocument) @foreach($receptionScreens as $receptionScreen)
<tr> <tr>
<th scope="row">{{ $onlineDocument->position }}</th> <th scope="row">{{ $receptionScreen->position }}</th>
<td>{{ $onlineDocument->name }}</td> <td>{{ $receptionScreen->name }}</td>
<td><a href="{{ route("admin-reception-screen.edit", $onlineDocument) }}" class="btn btn-secondary">редактировать</a> <td><a href="{{ route("admin-reception-screen.edit", $receptionScreen) }}" class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?" <a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('admin-reception-screen.destroy', $onlineDocument) }}" class="btn btn-danger"> href="{{ route('admin-reception-screen.destroy', $receptionScreen) }}" class="btn btn-danger">
удалить удалить
</a> </a>
</td> </td>
@if(count($onlineDocument->files) !== 0) @if(count($receptionScreen->files) !== 0)
</tr> </tr>
<tr> <tr>
<td colspan="3"> <td colspan="3">
@ -39,7 +39,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach($onlineDocument->files->sortBy('position') as $file) @foreach($receptionScreen->files->sortBy('position') as $file)
<tr> <tr>
<th scope="row">{{ $file->position }}</th> <th scope="row">{{ $file->position }}</th>
<td>{{ $file->name }}</td> <td>{{ $file->name }}</td>