<?php

namespace App\Http\Controllers;

use App\Models\LevelOfExperience;
use function request;

class LevelOfExperienceController extends Controller
{
    public function index()
    {
        return LevelOfExperience::all();
    }

    public function update(LevelOfExperience $levelOfExperience)
    {
        $this->validateRequest();
        $levelOfExperience->update(request()->attributes);
        return back(303)->with(['success' => 'success']);
    }

    public function validateRequest(): array
    {
        return request()->validate([
                'name_en' => 'required',
                'name_ar' => 'required',
                'sub_en' => 'required',
                'sub_ar' => 'required',
            ]

        );
    }

    public function store()
    {
        $attributes = $this->validateRequest();
        LevelOfExperience::create($attributes);
        return back(303)->with(['success' => 'success']);
    }

    public function destroy(LevelOfExperience $levelOfExperience)
    {
        $levelOfExperience->delete();
        return back(303)->with(['success' => 'success']);
    }
}
