<?php

namespace App\Http\Controllers\Hr;
use App\Http\Controllers\Controller;

use Illuminate\settings\Encryption\DecryptException;

use Illuminate\Http\Request;
use App\Http\Requests\SettingRequest;

use App\Setting;


use EF;

class SettingController extends Controller
{

	 public function index()
    {
    	$setting     = new Setting;

    	return view('hr.setting.manage_setting',
    		[
                'setting_list'     => $setting->getsettingList(),
    		]
    	);
    }

    public function storeSetting(SettingRequest $request)
    {

    	$form_collect = $request->input();

    	$setting      = new Setting;

    	$curr_setting = $setting->storeSetting($form_collect);

    	if (isset($curr_setting->id)) 
    	{
    	   parent::successMessage('Setting has been added');	
    	}

    	return redirect()->back();

    }

    public function updateSetting(SettingRequest $request)
    {
    	try
        {
                $form_collect     = $request->input();
            
         $form_collect['setting'] = decrypt($form_collect['setting']);

           
    		$setting      = new Setting;

    		$curr_setting = $setting->updateSetting($form_collect);

	    	if (isset($curr_setting->id)) 
	    	{
	    	 parent::successMessage('Setting has been updated');	
	    	}

    	}
    	catch(DecryptException $e)
    	{

    	}

    	return redirect()->back();
    }
    
}
