public function addNew($job, $data, $file)
 {
     if (!($contractor = \Contractor::getContractor())) {
         throw new \Exception("Current user is not a contractor.", 1);
         return;
     }
     if (!is_null($file)) {
         $uploader = new FileUploader();
         $location = 'uploads/contractors/' . $contractor->id . '/expense/' . date('m') . '/';
         try {
             $uploadedFile = $uploader->upload($file, $location, 'expense');
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), 1);
             return;
         }
     }
     $model = $this->getModel();
     $model->fill(['contractor_id' => $contractor->id, 'job_id' => $job->id, 'auth_company' => false, 'auth_agency' => is_null($job->agency_id) ? true : false, 'title' => $data['title'], 'amount' => $data['amount'], 'type' => $data['type'], 'file' => isset($uploadedFile) ? $uploadedFile : null, 'description' => $data['description'] !== '' ? $data['description'] : null]);
     if ($model->save()) {
         return $model;
     } else {
         throw new \Exception("Something wrong when saving data.", 1);
         return;
     }
 }
 public function addNew($job, $data, $file)
 {
     if (!($contractor = \Contractor::getContractor())) {
         throw new \Exception("Current user is not a contractor.", 1);
         return;
     }
     if (!is_null($file) && $data['timesheet_type'] === 'file') {
         $uploader = new FileUploader();
         $location = 'uploads/contractors/' . $contractor->id . '/timesheet/' . date('m') . '/';
         try {
             $uploadedFile = $uploader->upload($file, $location, 'resume');
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), 1);
             return;
         }
     }
     $model = $this->getModel();
     if ($data['timesheet_type'] === 'data') {
         $startDate = Carbon::createFromFormat('Y-m-d', $data['timesheet_date_from']);
         $endDate = Carbon::createFromFormat('Y-m-d', $data['timesheet_date_to']);
     }
     $model->fill(['contractor_id' => $contractor->id, 'job_id' => $job->id, 'auth_company' => false, 'auth_agency' => is_null($job->agency_id) ? true : false, 'name' => $data['timesheet_name'], 'type' => $data['timesheet_type'], 'file' => $data['timesheet_type'] === 'file' ? $uploadedFile : null, 'report' => $data['timesheet_type'] === 'data' ? $data['report_time'] : null, 'hours' => $data['timesheet_type'] === 'data' ? $data['num_hours'] : null, 'start_date' => isset($startDate) ? $startDate : null, 'end_date' => isset($endDate) ? $endDate : null]);
     if ($model->save()) {
         return $model;
     } else {
         throw new \Exception("Something wrong when saving data.", 1);
         return;
     }
 }
<?php

if (\User::check()) {
    $user = \User::getUser();
    if ($user->hasAccess('contractor')) {
        $contractor = \Contractor::getContractor();
    } elseif ($user->hasAccess('company')) {
        $company = \Company::getCompany();
    } elseif ($user->hasAccess('agency')) {
        $agency = \Agency::getAgency();
    }
}
$resources = \Site::getAllResources();
?>
	
@extends('front.app')

@section('title')
Free Resources | Programme Chameleon
@stop

@section('content')
<div id="wrapper">
	@include('front.include.header')
	<div class="container">
		<div id="free-resources-container">
			<h2 class="page-header">Free Resources</h2>
			<div class="tab-resources">
				<ul class="nav nav-tabs" role="tablist">
					<li role="presentation" class="active">
						<a href="#res-project" aria-controls="res-initiation" role="tab" data-toggle="tab">Project Management</a>
 public function postMarkNotif()
 {
     if (!($contractor = \Contractor::getContractor())) {
         return \Response::json(['type' => 'danger', 'message' => 'Not a contractor account']);
     }
     $contractor->notifications()->where('has_read', 0)->update(['has_read' => 1]);
     return \Response::json(['type' => 'success', 'message' => 'All notifications has been marked as "read"']);
 }
 public function postRemoveExpense()
 {
     $_hash = new Hash();
     $_hash = $_hash->getHasher();
     try {
         $contractor = \Contractor::getContractor();
         $id = $_hash->decode(\Input::get('i'));
         \Contractor::removeExpense($contractor, $id);
         return \Response::json(['type' => 'success', 'message' => 'Expense data removed from this job.']);
     } catch (\Exception $e) {
         return \Response::json(['type' => 'danger', 'message' => $e->getMessage()]);
     }
 }