本文整理汇总了PHP中Illuminate\Http\Request::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::user方法的具体用法?PHP Request::user怎么用?PHP Request::user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postAdd
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postAdd(Request $request, $product_id)
{
$deal = Deal::firstOrCreate(['user_id' => $request->user()->id, 'product_id' => $product_id]);
$product = \App\Product::find($product_id);
$request->session()->put("deals.{$product_id}", $product);
return response()->json(['id' => $product_id, 'mobile' => trans('products.mobile', ['mobile' => $request->user()->mobile]), 'text' => trans_choice('products.deal', $product->deals_count)]);
}
示例2: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user() == null || !$request->user()->is_admin) {
return redirect()->guest('auth/login');
}
return $next($request);
}
示例3: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user() && $request->user()->isAuthor()) {
return $next($request);
}
return redirect("/blog");
}
示例4: unfollow
public function unfollow(Request $request, User $user)
{
if ($request->user()->canUnfollow($user)) {
$request->user()->following()->detach($user);
}
return redirect()->back();
}
示例5: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 403);
} else {
return redirect()->guest('auth/login');
}
}
if (!$request->user()->isAdmin() && $request->user()->cannot('dashboard_view')) {
$this->auth->logout();
return redirect()->guest('auth/login')->withErrors(trans('messages.permission_denied'));
}
$route_array = explode('.', $request->route()->getName());
$permission_name = array_search($route_array[2], array_dot($this->permission_fields));
if ($permission_name) {
$route_array[2] = explode('.', $permission_name)[0];
}
// $route_name = implode('_', $route_array);
$route_name = $route_array[1] . '_' . $route_array[2];
if (!$request->user()->isAdmin() && $request->user()->cannot($route_name)) {
//PATCH 为null
if ($request->ajax()) {
return response()->json(['status' => trans('messages.permission_denied'), 'type' => 'error', 'code' => 403]);
} else {
return view('errors.403');
}
}
return $next($request);
}
示例6: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->user() || !$request->user()->is_admin) {
return redirect()->route('home')->with('warning-message', 'You are not authorized to access settings.');
}
return $next($request);
}
示例7: getIndex
public function getIndex(Request $request)
{
$perpage = 20;
$user = $request->user();
$mylogs = $request->user()->mylog()->where('mylog_action', '=', 'login')->orWhere('mylog_action', '=', 'logout')->orderBy('created_at', 'DESC')->paginate($perpage);
return view('manage.profile.index', ['TITLE' => '个人中心', 'META_KEYWORDS' => META_KEYWORDS, 'META_DESC' => META_DESC, 'PAGE_CODE' => '', 'user' => $user, 'mylogs' => $mylogs]);
}
示例8: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user() and !$request->user()->subscribed('main')) {
return redirect('subscribe');
}
return $next($request);
}
示例9: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->route('type') == "schede_tecniche" && (!$request->user() || !$request->user()->can("scarica_allegati"))) {
return redirect()->to('/?login=true');
}
return $next($request);
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $role
* @return mixed
*/
public function handle($request, Closure $next, $role = 1)
{
/**
* Account Role
* ------------
* 0 -> Member
* 1 -> Moderator
* 2 -> Admin
* 3 -> Super Admin
* 4 -> Lead Developer
*/
/**
* If Tampered role ie not in 0-4
*/
if ($request->user()->role > 4) {
return redirect('/')->withNotification("Sorry buddy! You are not authorized for that action.")->withType('warning');
}
/**
* Check for rights and with params if provided.
*/
if ($request->user()->role < $role) {
return redirect('/')->withNotification("Sorry buddy! You are not authorized for that action.")->withType('warning');
}
return $next($request);
}
示例11: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user()->role != 'administrator' && $request->user()->role != 'editor') {
return redirect('/');
}
return $next($request);
}
示例12: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user()->role == 'cliente' or $request->user()->role == 'socio') {
return $next($request);
}
return redirect('/');
}
示例13: handle
/**
* Run the request filter.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string $role
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user()->role != 'admin' && $request->user()->role != 'user') {
return Redirect::action('ClientController@index');
}
return $next($request);
}
示例14: store
public function store(Request $request, $id)
{
$orgOrder = OrganizationOrder::findOrFail($id);
$lineItem = new LineItem();
$lineItem->organization_order_id = $id;
if ($request->input('UserOrder') && strlen($request->input('UserOrder')['order']) > 0) {
if ($request->input('UserOrder')['default'] == 1) {
UserOrder::where('user_id', '=', $request->user()->id)->where('restaurant_id', '=', $orgOrder->restaurant()->id)->where('default', '=', '1')->update(['default' => 0]);
}
$userOrder = new UserOrder();
$userOrder->fill($request->input('UserOrder'));
$userOrder->user_id = $request->user()->id;
$userOrder->restaurant_id = $orgOrder->restaurant()->id;
$userOrder->save();
$lineItem->user_order = $userOrder->id;
} else {
$lineItem->user_order = $request->input('LineItem')['user_order'];
}
if ($lineItem->isValid()) {
$lineItem->save();
return redirect()->route('orgorder.show', ['orgId' => $orgOrder->organization()->id, 'id' => $lineItem->organization_order_id]);
} else {
return redirect()->route('lineitem.create', ['id' => $id])->withErrors($lineItem->getErrors())->withInput();
}
}
示例15: index
/**
* Display a listing of the resource.
*
* @param UserRepositoryInterface $userRepository
* @param ProjectRepositoryInterface $projectRepository
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(UserRepositoryInterface $userRepository, ProjectRepositoryInterface $projectRepository, Request $request)
{
$projects = $userRepository->drafts($request->user()->id);
$publishedProjects = $userRepository->published($request->user()->id);
$failedProjects = $userRepository->failed($request->user()->id);
return view('user.project.index', compact('projects', 'publishedProjects', 'failedProjects'));
}