79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Catalog;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use App\Http\Requests\StoreDepartmentRequest;
|
||
|
use App\Http\Requests\StoreDirectionRequest;
|
||
|
use App\Http\Requests\UpdateDepartmentRequest;
|
||
|
use App\Http\Requests\UpdateDirectionRequest;
|
||
|
use App\Models\Department;
|
||
|
use App\Models\Direction;
|
||
|
use Illuminate\Contracts\View\Factory;
|
||
|
use Illuminate\Contracts\View\View;
|
||
|
use Illuminate\Foundation\Application;
|
||
|
use Illuminate\Http\RedirectResponse;
|
||
|
|
||
|
class DirectionController extends Controller
|
||
|
{
|
||
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||
|
{
|
||
|
$directions = Direction::all();
|
||
|
return view('catalog.direction.index', compact('directions'));
|
||
|
}
|
||
|
|
||
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||
|
{
|
||
|
$departments = Department::pluck('name', 'id');
|
||
|
return view('catalog.direction.create', compact('departments'));
|
||
|
}
|
||
|
|
||
|
public function store(StoreDirectionRequest $request): RedirectResponse
|
||
|
{
|
||
|
$validated = $request->validated();
|
||
|
|
||
|
$direction = new Direction();
|
||
|
$direction->name = $validated['name'];
|
||
|
$direction->description = $validated['description'];
|
||
|
$direction->position = $validated['position'];
|
||
|
$direction->slug = $validated['slug'];
|
||
|
$direction->department_id = $validated['department_id'];
|
||
|
$direction->save();
|
||
|
|
||
|
return redirect()->route('directions.index');
|
||
|
}
|
||
|
|
||
|
public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||
|
{
|
||
|
return view('catalog.direction.show', compact('direction'));
|
||
|
}
|
||
|
|
||
|
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||
|
{
|
||
|
$departments = Department::pluck('name', 'id');
|
||
|
return view('catalog.direction.edit', compact('direction', 'departments'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Update the specified resource in storage.
|
||
|
*/
|
||
|
public function update(UpdateDepartmentRequest $request, Direction $direction)
|
||
|
{
|
||
|
$validated = $request->validated();
|
||
|
|
||
|
$direction->name = $validated['name'];
|
||
|
$direction->description = $validated['description'];
|
||
|
$direction->position = $validated['position'];
|
||
|
$direction->department_id = $validated['department_id'];
|
||
|
$direction->save();
|
||
|
|
||
|
return redirect()->route('directions.index');
|
||
|
}
|
||
|
|
||
|
public function destroy(Direction $direction): RedirectResponse
|
||
|
{
|
||
|
$direction->delete();
|
||
|
return redirect()->route('directions.index');
|
||
|
}
|
||
|
}
|