2024-02-10 11:23:38 +03:00
|
|
|
<?php
|
|
|
|
|
2024-02-12 10:58:48 +03:00
|
|
|
namespace App\Http\Controllers\admin\Catalog;
|
2024-02-10 11:23:38 +03:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2024-02-12 10:58:48 +03:00
|
|
|
use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
|
|
|
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
2024-02-10 11:23:38 +03:00
|
|
|
use App\Models\Department;
|
|
|
|
use App\Models\Direction;
|
2024-02-12 11:25:00 +03:00
|
|
|
use App\Models\Faculty;
|
2024-02-10 11:23:38 +03:00
|
|
|
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();
|
2024-02-12 10:58:48 +03:00
|
|
|
return view('admin.catalog.direction.index', compact('directions'));
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
|
|
|
$departments = Department::pluck('name', 'id');
|
2024-02-12 10:58:48 +03:00
|
|
|
return view('admin.catalog.direction.create', compact('departments'));
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2024-02-12 11:25:00 +03:00
|
|
|
$department = $direction->department;
|
|
|
|
$faculty = Faculty::find($department->faculty->id);
|
|
|
|
$educationalInstitution = $faculty->educationalInstitution;
|
|
|
|
return view(
|
|
|
|
'admin.catalog.direction.show',
|
|
|
|
compact(
|
|
|
|
'direction',
|
|
|
|
'educationalInstitution',
|
|
|
|
'faculty',
|
|
|
|
'department',
|
|
|
|
)
|
|
|
|
);
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
|
|
|
$departments = Department::pluck('name', 'id');
|
2024-02-12 10:58:48 +03:00
|
|
|
return view('admin.catalog.direction.edit', compact('direction', 'departments'));
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
2024-02-12 10:58:48 +03:00
|
|
|
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
2024-02-10 11:23:38 +03:00
|
|
|
{
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
|
|
|
$direction->name = $validated['name'];
|
|
|
|
$direction->description = $validated['description'];
|
|
|
|
$direction->position = $validated['position'];
|
2024-02-12 10:58:48 +03:00
|
|
|
$direction->slug = $validated['slug'];
|
2024-02-10 11:23:38 +03:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
}
|