first commit
This commit is contained in:
70
app/Http/Controllers/References/DepartmentController.php
Normal file
70
app/Http/Controllers/References/DepartmentController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\References;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\References\StoreDepartmentProfileRequest;
|
||||
use App\Http\Requests\References\StoreDepartmentRequest;
|
||||
use App\Models\Department;
|
||||
use App\Models\DepartmentProfile;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class DepartmentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the departments reference page.
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return Inertia::render('references/departments/Index', [
|
||||
'currentTeam' => $request->user()?->currentTeam
|
||||
? $request->user()?->toUserTeam($request->user()->currentTeam)
|
||||
: null,
|
||||
'departmentProfiles' => DepartmentProfile::query()
|
||||
->withCount('departments')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn (DepartmentProfile $departmentProfile) => [
|
||||
'id' => $departmentProfile->id,
|
||||
'name' => $departmentProfile->name,
|
||||
'departmentsCount' => $departmentProfile->departments_count,
|
||||
]),
|
||||
'departments' => Department::query()
|
||||
->with('departmentProfile:id,name')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn (Department $department) => [
|
||||
'id' => $department->id,
|
||||
'name' => $department->name,
|
||||
'isActive' => $department->is_active,
|
||||
'departmentProfile' => [
|
||||
'id' => $department->departmentProfile->id,
|
||||
'name' => $department->departmentProfile->name,
|
||||
],
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created department profile.
|
||||
*/
|
||||
public function storeProfile(StoreDepartmentProfileRequest $request): RedirectResponse
|
||||
{
|
||||
DepartmentProfile::create($request->validated());
|
||||
|
||||
return to_route('references.departments.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created department.
|
||||
*/
|
||||
public function store(StoreDepartmentRequest $request): RedirectResponse
|
||||
{
|
||||
Department::create($request->validated());
|
||||
|
||||
return to_route('references.departments.index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user