Example #1
0
 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
         $query->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
         flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     if ($role->users()->detach($user)) {
         flash()->success('Success!', 'Successfully removed user.');
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     flash()->error('Error!', 'There was an issue removing this user. Please try again.');
     return redirect()->route('admin.roles.show', [$roleId]);
 }
Example #2
0
 public function admins()
 {
     $admins = User::whereHas('roles', function ($q) {
         $q->where('name', 'web');
     })->get();
     return $admins;
 }
 /**
  * Returns a paginated list of all active talents
  *
  * @param null $tag
  * @param null $skill
  * @param null $location
  * @param null $orderBy
  * @param int $perPage
  * @param null $profession
  * @return \Illuminate\Pagination\Paginator
  */
 public function findActiveTalents($tag = null, $skill = null, $location = null, $orderBy = null, $perPage = 12, $profession = null)
 {
     $results = User::whereHas('profile', function ($q) use($tag, $skill, $location, $orderBy, $profession) {
         $q->where('published', '=', true);
         if ($location) {
             $q->where('location', '=', $location);
         }
         if ($tag) {
             $q->whereHas('tags', function ($q2) use($tag) {
                 $q2->where('tags.name', '=', $tag);
             });
         }
         if ($skill) {
             $q->whereHas('skill', function ($q) use($tag, $skill) {
                 $q->where('id', '=', $skill);
             });
         }
         if ($profession) {
             $q->where('profession_id', '=', $profession);
         }
     })->with('ratings')->with('profile');
     if ($orderBy) {
         $results->orderBy($orderBy);
     } else {
         $results->orderBy('id', 'DESC');
     }
     $paginatedResults = $results->paginate($perPage);
     if ($skill or $tag) {
         $paginatedResults->appends(['needs' => $skill, 'tag' => $tag]);
     }
     return $paginatedResults;
 }
Example #4
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     // Set the inquiry model data.
     $this->inquiry->user_id = auth()->id();
     $this->inquiry->uuid = uuid();
     $this->inquiry->category_id = $this->category->id;
     $this->inquiry->title = $this->request->input('title');
     $this->inquiry->description = $this->request->input('description');
     if ($this->category->manager === true) {
         // If the category requires manager approval, we'll retrieve the manager record.
         $manager = User::whereHas('roles', function (Builder $query) {
             $query->whereName('managers');
         })->findOrFail($this->request->input('manager'));
         $this->inquiry->manager_id = $manager->id;
         // We'll send the manager a notification.
         $notification = new Notification($manager, 'emails.inquiries.created', ['inquiry' => $this->inquiry], function (Message $message) use($manager) {
             $message->subject('A New Request Requires Your Approval');
             $message->to($manager->email);
         });
     }
     if ($this->inquiry->save()) {
         // If the inquiry was successfully created, we'll
         // send out the notification if one has been set.
         if (isset($notification)) {
             $this->dispatch($notification);
         }
         return true;
     }
     return false;
 }
 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @throws CannotRemoveRolesException
  *
  * @return int
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) {
         $builder->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role from this user. You're the only administrator.");
     }
     return $role->users()->detach($user);
 }
Example #6
0
 public function apiGetResearcher(Request $request, $keyword = null)
 {
     /* @var Role $researchers */
     $researchers = Role::where("key", "=", "researcher")->first();
     if ($keyword == null) {
         $users = $researchers->users()->get();
     } else {
         $users = User::whereHas("roles", function ($query) {
             $query->where('key', '=', 'researcher');
         })->where("firstname", "LIKE", "%{$keyword}%")->orWhere("lastname", "LIKE", "%{$keyword}%")->get();
     }
     return $users;
 }
Example #7
0
 /**
  * Execute the job.
  *
  * @throws CannotRemoveRolesException
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name', $this->user->name);
     $this->user->email = $this->request->input('email');
     $password = $this->request->input('password');
     // Verify before changing the users password that it's not empty.
     if (!empty($password)) {
         // If the user doesn't have a set password mutator,
         // we'll encrypt the password.
         if (!$this->user->hasSetMutator('password')) {
             $password = bcrypt($password);
         }
         $this->user->password = $password;
     }
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     $roles = $this->request->input('roles', []);
     // Retrieve all administrator users.
     $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) {
         $builder->whereName($adminName);
     })->get();
     // Retrieve the administrator role.
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if (count($roles) === 0 && $this->user->hasRole($admin) && $this->user->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role. You're the only administrator.");
     }
     if ($this->user->save()) {
         $this->user->roles()->sync($roles);
         return true;
     }
     return false;
 }
Example #8
0
 public function findOrCreateByVk($data) : User
 {
     $user = User::whereHas('connections', function ($query) use($data) {
         $query->where('driver', 'vk');
         $query->whereRaw('cast(("socials".data->>\'id\') as varchar) = ?', [$data->id]);
     })->first();
     if (!empty($user)) {
         return $user;
     }
     $user = User::whereIn('username', [$data->nickname, $data->email])->first();
     if (!empty($user)) {
         $this->addConnection($user, 'vk', $data);
         return $user;
     }
     /** @var User $user */
     $user = User::create(['first_name' => $data->user['first_name'], 'last_name' => $data->user['last_name'], 'username' => $data->nickname ?? $data->email, 'avatar' => $data->avatar]);
     $this->addConnection($user, 'vk', $data);
     return $user;
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $author = User::whereHas('role', function ($q) {
         $q->where('slug', 'admin');
     })->first();
     $categories = Category::where('is_active', 1)->get();
     $postsRecents = Post::where('is_active', 1)->where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get();
     $postsPopular = Post::where('is_active', 1)->where('seen', 1)->orderBy('nview', 'desc')->take(3)->get();
     $commentsRecents = Comment::where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get();
     $tags = Tag::all();
     $INFO_SITE = Admin::first();
     view()->share('author', $author);
     view()->share('categories', $categories);
     view()->share('tags', $tags);
     view()->share('postsRecents', $postsRecents);
     view()->share('postsPopular', $postsPopular);
     view()->share('commentsRecents', $commentsRecents);
     view()->share('INFO_SITE', $INFO_SITE);
 }
 /**
  * 关联查询
  *
  *  article 为 User 模型 里面的 article() 方法
  *
  */
 public function queryRelation()
 {
     //select `username` from `tcc_users` where (select count(*) from `article` where `article`.`user_id` = `tcc_users`.`id`) > 5
     $user = User::has('article', '>', 5)->select('username')->get();
     debug($user);
     $user = User::whereHas('article', function ($query) {
         $query->where('content', 'like', '%content%');
     })->get();
     debug($user);
     return view('index');
 }
Example #11
0
 public function getAllStats()
 {
     $users = User::whereHas('roles', function ($q) {
         $q->where('name', 'hacker');
     })->with('application', 'application.school')->get();
     $gender = array();
     $grad_year = array();
     $school = array();
     $completed = array(0, 0);
     foreach ($users as $user) {
         if ($user->application->completed) {
             if (!isset($gender[$user->application->gender])) {
                 $gender[$user->application->gender] = 1;
             } else {
                 $gender[$user->gender]++;
             }
             if (!isset($grad_year[$user->application->grad_year])) {
                 $grad_year[$user->application->grad_year] = 1;
             } else {
                 $grad_year[$user->application->grad_year]++;
             }
             if (!isset($school[$user->application->school])) {
                 $school[$user->application->school] = 1;
             } else {
                 $school[$user->application->school]++;
             }
             $completed[1]++;
         } else {
             $completed[0]++;
         }
     }
     var_dump($gender);
     var_dump($grad_year);
     // var_dump($school);
     var_dump($completed);
 }
Example #12
0
 public function sortUser($slug)
 {
     $users = User::whereHas('role', function ($q) use($slug) {
         $q->where('slug', $slug);
     })->orderBy('seen', 'asc')->orderBy('created_at', 'desc')->paginate($this->itemPerPage);
     $roles = Role::all();
     $counts['total'] = User::count();
     foreach ($roles as $role) {
         $slug = $role->slug;
         $counts[$slug] = User::whereHas('role', function ($q) use($slug) {
             $q->whereSlug($slug);
         })->count();
     }
     return view('admin.users.index', compact('users', 'roles', 'counts'));
 }
Example #13
0
 public function getDaftarGuruInstansi($instansiId = null)
 {
     if ($instansiId == null) {
         return '';
     }
     $data = ['guru' => User::whereHas('guru', function ($query) use($instansiId) {
         return $query->where('instansi_id', $instansiId);
     })->get()];
     return view('backend.pages.undangan.guru-instansi', $data);
 }
Example #14
0
 /**
  * Returns a new form for the specified inquiry.
  *
  * @param Inquiry  $inquiry
  * @param Category $category
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function form(Inquiry $inquiry, Category $category)
 {
     return $this->form->of('inquiries', function (FormGrid $form) use($inquiry, $category) {
         if ($inquiry->exists) {
             $method = 'PATCH';
             $url = route('inquiries.update', [$inquiry->id]);
             $form->submit = 'Save';
         } else {
             $method = 'POST';
             $url = route('inquiries.store', [$category->id]);
             $form->submit = 'Create';
         }
         $form->attributes(compact('method', 'url'));
         $form->with($inquiry);
         $form->fieldset(function (Fieldset $fieldset) use($inquiry, $category) {
             $fieldset->control('input:text', 'title')->attributes(['placeholder' => 'Enter the title of your request.']);
             if ($category->manager) {
                 $fieldset->control('input:select', 'manager', function (Field $field) use($inquiry) {
                     $field->label = 'Manager';
                     $field->options = User::whereHas('roles', function (Builder $query) {
                         $query->whereName('Managers');
                     })->orderBy('name')->pluck('name', 'id');
                     $field->value = function (Inquiry $inquiry) {
                         return $inquiry->manager_id;
                     };
                     if ($inquiry->category_id) {
                         $field->attributes = ['disabled'];
                     }
                 });
             }
             $fieldset->control('input:textarea', 'description')->attributes(['placeholder' => 'Enter the description of your request.']);
         });
     });
 }