當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Guard::user方法代碼示例

本文整理匯總了PHP中Illuminate\Auth\Guard::user方法的典型用法代碼示例。如果您正苦於以下問題:PHP Guard::user方法的具體用法?PHP Guard::user怎麽用?PHP Guard::user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Auth\Guard的用法示例。


在下文中一共展示了Guard::user方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: grantedRoles

 /**
  * Get all roles of the current user
  * @return array
  */
 protected function grantedRoles()
 {
     $userRoles = $this->guard->user()->roles->toArray();
     return array_map(function ($roles) {
         return $roles['pivot']['role_id'];
     }, $userRoles);
 }
開發者ID:jraymundoyrockdev,項目名稱:api-gfccm-systems,代碼行數:11,代碼來源:IndexShowCreateUpdateAuth.php

示例2: store

 /**
  * Store a newly created snippet in storage.
  *
  * @param SnippetsRequest $request
  * @return Response
  */
 public function store(SnippetsRequest $request, Guard $auth)
 {
     $data = ['user_id' => $auth->user() ? $auth->user()->id : null];
     $snippet = $this->dispatchFrom(StoreNewSnippetCommand::class, $request, $data);
     flash('Snippet was successfully created.');
     return redirect()->route('snippets.show', $snippet->slug->slug);
 }
開發者ID:elvios,項目名稱:darkshare,代碼行數:13,代碼來源:SnippetsController.php

示例3: authorize

 /**
  * Authorize the post.
  *
  * @param PostInterface $post
  */
 public function authorize(PostInterface $post)
 {
     if (!$post->isEnabled() && !$this->guard->user()) {
         abort(404);
     }
     $this->authorizer->authorize('anomaly.module.posts::view_drafts');
 }
開發者ID:bloveless,項目名稱:posts-module,代碼行數:12,代碼來源:PostAuthorizer.php

示例4: authorize

 /**
  * Authorize the page.
  *
  * @param PageInterface $page
  */
 public function authorize(PageInterface $page)
 {
     /* @var UserInterface $user */
     $user = $this->guard->user();
     /**
      * If the page is not enabled and we
      * are not logged in then 404.
      */
     if (!$page->isEnabled() && !$user) {
         abort(404);
     }
     /**
      * If the page is not enabled and we are
      * logged in then make sure we have permission.
      */
     if (!$page->isEnabled()) {
         $this->authorizer->authorize('anomaly.module.pages::view_drafts');
     }
     /**
      * If the page is restricted to specific
      * roles then make sure our user is one of them.
      */
     $allowed = $page->getAllowedRoles();
     if (!$allowed->isEmpty() && (!$user || !$user->hasAnyRole($allowed))) {
         $page->setResponse($this->response->redirectTo('login'));
     }
 }
開發者ID:visualturk,項目名稱:pages-module,代碼行數:32,代碼來源:PageAuthorizer.php

示例5: store

 /**
  * Store a newly created snippet in storage.
  *
  * @param SnippetsRequest $request
  * @return Response
  */
 public function store(SnippetsRequest $request)
 {
     $this->auth->basic('username');
     $data = ['title' => $request->input('title') ?: null, 'user_id' => $this->auth->user() ? $this->auth->id() : null, 'password' => $request->input('password') ?: null, 'mode' => $request->input('mode') ?: 'markdown'];
     $snippet = $this->dispatchFrom(StoreNewSnippetCommand::class, $request, $data);
     return 'http://drk.sh/s/' . $snippet->slug->slug . PHP_EOL;
 }
開發者ID:elvios,項目名稱:darkshare,代碼行數:13,代碼來源:SnippetsController.php

示例6: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check() && $this->auth->user()['status'] === 'student') {
         return $next($request);
     }
     Session::push('messages', 'danger|Vous devez être étudiant pour accéder à cette page');
     return redirect('/');
 }
開發者ID:Kocal,項目名稱:IUT-MethodoProd-QCM,代碼行數:16,代碼來源:Student.php

示例7: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user = $this->auth->user();
     if ($user->user_type != SiteConstants::USER_ADMIN) {
         return redirect('auth/logout');
     }
     return $next($request);
 }
開發者ID:talenthub2015,項目名稱:talenthub-website,代碼行數:15,代碼來源:Admin.php

示例8: handle

 /**
  * Handle incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // check if this an auth.shield instance
     if ($this->config->get('auth.driver') === 'classid.shield') {
         $this->auth->user();
     }
     return $next($request);
 }
開發者ID:classid,項目名稱:core-auth,代碼行數:16,代碼來源:ResolveAuthUser.php

示例9: __construct

 /**
  * Create a new PreferenceRepositoryInterface instance.
  *
  * @param Guard           $auth
  * @param PreferenceModel $model
  */
 public function __construct(Guard $auth, PreferenceModel $model)
 {
     $this->auth = $auth;
     $this->model = $model;
     $this->preferences = new PreferenceCollection();
     if ($user = $this->auth->user()) {
         $this->preferences = $this->model->belongingToUser($auth->getUser())->get();
     }
 }
開發者ID:visualturk,項目名稱:preferences-module,代碼行數:15,代碼來源:PreferenceRepository.php

示例10: show

 public function show($id, Guard $auth)
 {
     if ($auth->user()->id == $id) {
         $personne = User::findOrFail($id);
         return view('parents.show', compact('personne'));
     }
     $personne = User::findOrFail($auth->user()->id);
     return redirect()->action('UserController@show', $auth->user()->id);
 }
開發者ID:InfoTeamUPS,項目名稱:projetTarabel,代碼行數:9,代碼來源:UserController.php

示例11: save

 /**
  * Save activity
  *
  * @param $activity
  * @return bool
  */
 public function save($activity)
 {
     $activity['user_id'] = null;
     $user = $this->auth->user();
     if (isset($user->id)) {
         $activity['user_id'] = $user->id;
     }
     return $this->activity->create($activity) ? true : false;
 }
開發者ID:sadhakbj,項目名稱:resourcecontracts.org,代碼行數:15,代碼來源:ActivityRepository.php

示例12: update

 /**
  * @param Post $post
  * @param array $attributes
  * @return static
  */
 public function update($post, array $attributes = array())
 {
     $attributes['created_by'] = $this->user->user()->id;
     if (!isset($attributes['state']) || empty($attributes['state'])) {
         $attributes['state'] = 0;
     }
     $post->update($attributes);
     return $post;
 }
開發者ID:vnzacky,項目名稱:dog,代碼行數:14,代碼來源:EloquentPostRepository.php

示例13: __construct

 /**
  * @param UserService    $user
  * @param CountryService $country
  * @param Guard          $auth
  */
 public function __construct(UserService $user, CountryService $countries, Guard $auth)
 {
     $this->middleware('auth');
     $this->user = $user;
     $this->auth = $auth;
     if (!$this->auth->user()->hasRole(['superadmin', 'admin', 'country-admin'])) {
         return redirect('/home')->withError(trans('contract.permission_denied'))->send();
     }
     $this->countries = $countries;
 }
開發者ID:sadhakbj,項目名稱:resourcecontracts.org,代碼行數:15,代碼來源:UserController.php

示例14: handle

 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         return redirect()->guest('login');
     }
     if ($this->auth->check() && !$this->auth->user()->isAdmin()) {
         App::abort('403');
     }
     return $next($request);
 }
開發者ID:studiocaro,項目名稱:HorseStories,代碼行數:10,代碼來源:Admin.php

示例15: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check()) {
         if ($this->auth->user()->allowRoutes($request->route()->getName())) {
             return $next($request);
         }
         return response('Forbidden.', 403);
     }
     return $next($request);
 }
開發者ID:bitw,項目名稱:acl-example,代碼行數:17,代碼來源:Access.php


注:本文中的Illuminate\Auth\Guard::user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。