<?php

namespace App\Http\Controllers\HR;

use App\Model\Hr\HrHardSkill;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class HrHardSkillController extends Controller
{

    public function index()
    {
        $hard_skill = HrHardSkill::get();
        return view('hr.hard-skill.index', compact('hard_skill'));
    }


    public function create()
    {
        return view('hr.hard-skill.create');
    }


    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);

        try{
            $hard_skill = new HrHardSkill();
            $hard_skill->name = $request->name;
            $hard_skill->note = $request->note;
            $hard_skill->save();

            return redirect()->route('hr-hard-skill.index')->with('Success', 'Added Successful!');
        }catch(\Exception $ex){
            return back()->withErrors($ex->getMessage())->withInput();
        }
    }

    public function show(HrHardSkill $hrHardSkill)
    {
        //
    }


    public function edit($id)
    {
        $hard_skill = HrHardSkill::find($id);
        return view('hr.hard-skill.edit', compact('hard_skill'));
    }


    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' => 'required'
        ]);

        try{
            $hard_skill = HrHardSkill::find($id);
            $hard_skill->name = $request->name;
            $hard_skill->note = $request->note;
            $hard_skill->update();

            return redirect()->route('hr-hard-skill.index')->with('Success', 'Updated Successful!');
        }catch(\Exception $ex){
            return back()->withErrors($ex->getMessage())->withInput();
        }
    }


    public function destroy(HrHardSkill $hrHardSkill)
    {
        //
    }
}
