/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // list of all tools if (\Auth::user()->admin == "No" && \Auth::user()->super == "No") { $tools = \Auth::user()->tools()->orderBy('retag_date', 'ASC')->get(); } else { $type = \Request::get("type"); if (\Auth::user()->admin == "Yes") { if ($type == "Personal") { $tools = \Auth::user()->tools()->where("type", "=", "Personal")->orderBy('retag_date', 'ASC')->get(); } else { $tools = \App\Models\Tool::whereIn("user_id", function ($query) { $query->select('id')->from("users")->where('site_id', \Auth::user()->site_id); // ->where(function ($query) { // $query->where('admin',"=","Yes") // ->orWhere('super',"=","Yes") // }); })->where("type", "=", "Company")->orderBy('retag_date', 'ASC')->get(); } } if (\Auth::user()->super == "Yes") { if ($type == "Personal") { $tools = \Auth::user()->tools()->where("type", "=", "Personal")->orderBy('retag_date', 'ASC')->get(); } else { $tools = \App\Models\Tool::whereIn("user_id", function ($query) { $query->select('users.id')->from("users")->join("sites", "site_id", "=", "sites.id")->where('company_id', \Auth::user()->site->company_id); })->where("type", "=", "Company")->orderBy('retag_date', 'ASC')->get(); } } } return view('allTools', ['tools' => $tools]); }
Route::get('countduepersonaltools', function () { $user = \Auth::user(); $FiveDaystoGo = \Carbon\Carbon::now()->addDays(5)->format("Y-m-d"); $usertools = $user->tools()->where('type', 'Personal')->where("retag_date", "<=", $FiveDaystoGo)->count(); return $usertools; }); Route::get('countduecompanytools', function () { $user = \Auth::user(); $FiveDaystoGo = \Carbon\Carbon::now()->addDays(5)->format("Y-m-d"); if ($user->admin == 'Yes') { $companytools = \App\Models\Tool::whereIn("user_id", function ($query) { $query->select('id')->from("users")->where('site_id', \Auth::user()->site_id); })->where("type", "=", "Company")->where("retag_date", "<=", $FiveDaystoGo)->count(); } else { $companytools = \App\Models\Tool::whereIn("user_id", function ($query) { $query->select('users.id')->from("users")->join("sites", "site_id", "=", "sites.id")->where('company_id', \Auth::user()->site->company_id); })->where("type", "=", "Company")->where("retag_date", "<=", $FiveDaystoGo)->count(); } return $companytools; }); Route::get('countusers', function () { $user = \Auth::user(); if ($user->admin == 'Yes') { $users = \App\Models\User::whereIn("id", function ($query) { $query->select('id')->from("users")->where('site_id', \Auth::user()->site_id); })->count(); } else { $users = \App\Models\User::whereIn("id", function ($query) { $query->select('users.id')->from("users")->join("sites", "site_id", "=", "sites.id")->where('company_id', \Auth::user()->site->company_id); })->count(); }