<?php

namespace App\Http\Controllers\HR;

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

class HrSoftSkillController extends Controller
{

    public function index()
    {
        $soft_skill = HrSoftSkill::get();
        return view('hr.soft-skill.index',compact('soft_skill'));
    }


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


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

        try{
            $soft_skill = new HrSoftSkill();
            $soft_skill->name = $request->name;
            $soft_skill->note = $request->note;
            $soft_skill->save();

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


    public function show(HrSoftSkill $hrSoftSkill)
    {
        //
    }


    public function edit($id)
    {
        $soft_skill = HrSoftSkill::find($id);
        return view('hr.soft-skill.edit', compact('soft_skill'));
    }


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

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

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


    public function destroy(HrSoftSkill $hrSoftSkill)
    {
        //
    }
}
