<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\GlobalPreference;
use App\Http\Requests\GlobalPreferenceRequest;
use Auth;

class GlobalPreferenceController extends Controller
{
	public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
		if(Auth::user()->role->role_permission('view_global')){
			$global = GlobalPreference::first();
            return view('global.edit', compact('global'));
		}else{
			abort(403);
		}
    }

    	
    public function update(GlobalPreferenceRequest $request, GlobalPreference $global)
    {
		if(Auth::user()->role->role_permission('edit_global')){
			$global->update($request->all());
			return redirect('global')->withSuccess('Global Preference has been updated.');
		}else{
			abort(403);
		}
    }

}