%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/hr/api/app/Http/Controllers/Api/v1/
Upload File :
Create Path :
Current File : /var/www/html/hr/api/app/Http/Controllers/Api/v1/WorkingDaysController.php

<?php

namespace App\Http\Controllers\Api\v1;


use App\Http\Controllers\Api\ApiController;
use App\Http\Requests\Api\v1\WorkingDays\CreateWorkingDayRequest;
use App\Models\WorkingDay;
use App\Transformers\DayTransformer;
use App\Transformers\WorkingDayTransformer;
use Throwable;

class WorkingDaysController extends ApiController
{
    /**
     * @var DayTransformer
     */
    private $transformer;

    public function __construct(WorkingDayTransformer $transformer)
    {
        $this->transformer = $transformer;
    }

    public function index()
    {
        $days = WorkingDay::all();
        return $this->collection($days, $this->transformer);
    }

    public function show($day)
    {
        $day = WorkingDay::query()
                         ->findOrFail($day);
        return $this->item($day, $this->transformer);
    }

    public function store(CreateWorkingDayRequest $request)
    {
        try {
            $day = WorkingDay::createItem($request->only([
                'day_id',
                'starts_at',
                'ends_at',
                'has_shifts',
                'valid_from',
                'valid_to',
            ]));
            return $this->item($day, $this->transformer);
        } catch (Throwable $e) {
            return $this->wrongArguments([
                'message' => $e->getMessage(),
            ]);
        }
    }

    public function update(CreateWorkingDayRequest $request, $day)
    {
        try {
            /** @var WorkingDay $day */
            $day = WorkingDay::query()
                             ->findOrFail($day);
            $day->updateItem($request->only([
                'day_id',
                'starts_at',
                'ends_at',
                'has_shifts',
                'valid_from',
                'valid_to',
            ]));
            return $this->item($day, $this->transformer);
        } catch (Throwable $e) {
            return $this->wrongArguments([
                'message' => $e->getMessage(),
            ]);
        }
    }

    public function destroy($day)
    {
        WorkingDay::destroy($day);
        return $this->noContent();
    }

}

Zerion Mini Shell 1.0