本文整理汇总了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);
}
示例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);
}
示例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');
}
示例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'));
}
}
示例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;
}
示例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('/');
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}