<?php

namespace App\Http\Controllers\HR;

use App\Model\Hr\HrResignModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;

class HrEmployeeResignController extends Controller
{
    public function index()
    {
        # code...
    }
    public function create()
    {

    }

    public function store()
    {


    }

    public function edit($id)
    {

        $emp_resign = HrResignModel::find($id);
        return view('hr.employee-resign.edit', compact('emp_resign','id'));

    }

    public function update(Request $request, $id)
    {

        $this->validate($request, [
            'reason' => 'required',
            'status' => 'required',
            'type'   => 'required'
        ]);

        try{
            $emp_resign = HrResignModel::find($id);
            $emp_code     = $emp_resign->code;

            $employee = User::where('code','=',$emp_code)->first();
            $employee->status = $request->status;
            $employee->update();

            return redirect()->route('hr-resign.index')->with('success','Update Successful!.');
        }catch(\Exception $ex){
            return back()->withErrors($ex->getMessage())->withInput();
        }
    }
}
