#23 - wip
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Inertia\Response;
|
||||
use Toby\Http\Resources\VacationLimitResource;
|
||||
use Toby\Http\Resources\YearPeriodResource;
|
||||
use Toby\Models\YearPeriod;
|
||||
|
||||
class VacationDaysController extends Controller
|
||||
{
|
||||
public function edit(Request $request): Response
|
||||
{
|
||||
$year = $request->query("year", Carbon::now()->year);
|
||||
|
||||
/** @var YearPeriod $yearPeriod */
|
||||
$yearPeriod = YearPeriod::query()->where("year", $year)->firstOrFail();
|
||||
$previousYearPeriod = YearPeriod::query()->where("year", $year - 1)->first();
|
||||
$nextYearPeriod = YearPeriod::query()->where("year", $year + 1)->first();
|
||||
|
||||
|
||||
return inertia("VacationDays", [
|
||||
"vacationLimits" => VacationLimitResource::collection($yearPeriod->vacationLimits()->with("user")->get()),
|
||||
"yearPeriods" => [
|
||||
"prev" => $previousYearPeriod ? new YearPeriodResource($previousYearPeriod) : null,
|
||||
"current" => new YearPeriodResource($yearPeriod),
|
||||
"next" => $nextYearPeriod ? new YearPeriodResource($nextYearPeriod) : null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
dump($request->get("items"));
|
||||
}
|
||||
}
|
35
app/Http/Controllers/VacationLimitController.php
Normal file
35
app/Http/Controllers/VacationLimitController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Arr;
|
||||
use Inertia\Response;
|
||||
use Toby\Http\Requests\VacationLimitRequest;
|
||||
use Toby\Http\Resources\VacationLimitResource;
|
||||
use Toby\Models\VacationLimit;
|
||||
|
||||
class VacationLimitController extends Controller
|
||||
{
|
||||
public function edit(): Response
|
||||
{
|
||||
return inertia("VacationLimits", [
|
||||
"limits" => VacationLimitResource::collection(VacationLimit::query()->with("user")->get()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(VacationLimitRequest $request): RedirectResponse
|
||||
{
|
||||
foreach ($request->data() as $data) {
|
||||
$limit = VacationLimit::query()->find($data["id"]);
|
||||
|
||||
$limit->update(Arr::only($data, ["has_vacation", "days"]));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with("success", __("Vacation limits have been updated"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user