<?php

namespace App\Modules\Hr\controllers;

use Illuminate\Support\Facades\View;
use App\Http\Controllers\BaseController;
use App\Modules\Hr\UserDetails;

class HrController extends BaseController
{
    /**
     *	The layout that should be used for responses.
     */
    protected $layout = 'layouts.master';

    public function getIndex()
    {
        // Grab the user details
        // or create a new record if it doesn't exist
        $user_details = UserDetails::find(getAuthUserId());

        if (! $user_details) {
            $user_details = UserDetails::create(['user_id' => getAuthUserId()]);
            $user_details = UserDetails::find(getAuthUserId()); // fetch it again with all the attributes
        }

        // Load user data
        $user_details->load('user');

        $this->layout->content = View::make('hr::index', compact('user_details'));
    }
}
