public function __construct() { $this->middleware('auth'); $this->user = Auth::user(); $this->data['tabs'] = Tab::orderBy('order')->get(); $this->data['current_tab'] = 20; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('/login'); } } else { if (Auth::user()->isStaff() || Auth::user()->isAdmin()) { $user = Auth::user(); $tabs = $user->current_role->tabs; $forbid_urls = []; if ($user->role != 2) { $forbid_urls[] = 'manage/quan-li-nhan-su'; } $allow_urls = $tabs->pluck('url')->toArray(); $allTabs_urls = Tab::where('id', '!=', 1)->where('id', '!=', 2)->get()->pluck('url')->toArray(); foreach ($allTabs_urls as $url) { if (!in_array($url, $allow_urls)) { $forbid_urls[] = $url; } } if (in_array($request->path(), $forbid_urls)) { return redirect('/'); } return $next($request); } else { return redirect('/'); } } }
public function tabs() { $tabs = Tab::all(); $tabs = $tabs->map(function ($tab) { $tab->checked = false; return $tab; }); return response()->json($tabs, 200); }
/** * Create a new controller instance. * * @return void */ public function __construct() { // $this->middleware('auth'); $this->s3_url = config('app.s3_url'); $this->middleware('is_staff'); $this->user = Auth::user(); if ($this->user) { $tabs_ids = $this->user->current_role->tabs->pluck('id'); $parent_tabs_id = $this->user->current_role->tabs->pluck('parent_id'); $allow_tabs = array_merge($tabs_ids->toArray(), $parent_tabs_id->toArray()); $allow_tabs[] = 1; if ($this->user->role == 2) { $allow_tabs[] = 2; } $tabs = Tab::orderBy('order')->whereIn('id', $allow_tabs)->get(); $this->data['tabs'] = $tabs; } }
/** * Execute the console command. * * @return mixed */ public function handle() { $date = new \DateTime(); $date->modify('+3 days'); $formatted_date_from = $date->format('Y-m-d'); $date->modify('+6 days'); $formatted_date_to = $date->format('Y-m-d'); $dates = createDateRangeArray(strtotime($formatted_date_from), strtotime($formatted_date_to)); $bases = Base::where('center', 1)->get(); $current_gen = Gen::getCurrentGen(); $shiftSessions = ShiftSession::where('active', 1)->get(); $lastShift = Shift::where('gen_id', $current_gen->id)->orderBy('week', 'desc')->first(); $week = $lastShift ? $lastShift->week : 0; foreach ($dates as $date) { foreach ($bases as $base) { foreach ($shiftSessions as $shiftSession) { $shift = new Shift(); $shift->gen_id = $current_gen->id; $shift->base_id = $base->id; $shift->shift_session_id = $shiftSession->id; $shift->week = $week + 1; $shift->date = $date; $shift->save(); } } } $role_ids = Tab::find(35)->roles->pluck('id')->unique()->toArray(); $roles = Role::whereIn('id', $role_ids)->get(); if ($week == 0) { $week = 1; } foreach ($roles as $role) { $users = $role->users; foreach ($users as $user) { send_mail_regis_shift($user, $week, $current_gen, ['*****@*****.**']); } } $this->info('done'); }
/** * deleteTab function. * * @access public * @param int $id * @return void */ public function deleteTab($id) { $tab = Tab::find($id); $tab->delete(); }
public function show_tabs() { $this->data['current_tab'] = 3; $tabs = $this->data['tabs']; foreach ($tabs as $tab) { if ($tab->parent_id == 0) { $tab->parent_name = "None"; } else { $tab->parent_name = Tab::find($tab->parent_id)->name; } } return view('role_management/show_tabs', $this->data); }