- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我目前正在试验新的 Laravel 5 并让身份验证工作(注册/登录)。
为了在我的 Controller 中获得经过身份验证的用户,我目前将 Guard
注入(inject)到 Controller 操作中:
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
class ClientController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Guard $auth)
{
return view('client.index', ['user' => $auth->user()]);
}
...
第一个问题:这是推荐的方式吗?
第二个问题:我将如何实现某种角色/权限?像 client.edit
, client.add
, ... Larval 5 在这里提供某种便利吗?我将如何为路由/ Controller 操作设置必要的角色/权限?
我在想我可能需要为此编写自己的中间件。关于如何解决这个问题有什么建议吗?
最佳答案
在 Laravel 5 上花了一些时间后,我可以回答我自己的问题:
注入(inject) Guard
是推荐的方式吗? 否:如果你需要在你的 View 中访问 Auth
,你已经可以这样做了:
@if( Auth::check() )
Current user: {{ Auth::user()->name }}
@endif
这使用 Auth
外观。所有可用外观的列表在 config/app.php
中的 aliases:
如果我在 Controller 中需要 Auth
怎么办? 像问题中所示注入(inject) Guard
的实例有效,但您不需要需要。您可以像在模板中那样使用 Auth
外观:
public function index()
{
if(\Auth::check() && \Auth::user()->name === 'Don') {
// Do something
}
return view('client.index');
}
请注意,由于 L5 使用命名空间,因此在外观名称之前需要 \
。
我想使用 L5 中的新身份验证机制获得权限/角色: 我使用新的中间件实现了一个轻量级权限模块,它被称为 Laraguard。在 Github 上查看并告诉我您的想法:https://github.com/cgrossde/Laraguard
更新:为了完整起见,我想再提两个项目。它们提供了您在数据库中保存角色和权限所需的一切,并与 Laraguard 完美地协同工作或单独工作:
关于php - Laravel 5 新的身份验证 : Get current user and how to implement roles?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27571573/
我有一个 jQuery 日期选择器。我想将默认日期设置为“当前月份、当前日期(当前年份-18)”,但在设置 defaultDate 属性时遇到问题。显示的默认年份是 1920 年,据说是 1995 年
我有下面的 C 程序来实现升序链表。问题出在 buildList() 函数中,因此您可以忽略除 main() 和 buildList() 之外的其他函数。 #include #include stru
嗯,想象一下 current.txt 文件: asdf base.txt 文件: asdf 其他.txt文件: asdf 当我进行三向 merge 时 git merge-file current.t
我试图在鼠标悬停时生成一个 :after 伪元素。例如: .email{ width:100px; overflow:hidden; text-overflow:ellipsi
为什么 $('a.current').removeClass('current'); 不适用于此 jquery 选项卡? http://jsfiddle.net/laukstein/ytnw9/8/
我正在创建一个应用程序(Outlook 的 Office 加载项) 我遇到的问题是更新我的屏幕。我知道我需要调用 Dispatcher,但是它在我的 ViewModel 中始终为 null p
我为客户开发网络和移动应用程序。在我当前的架构中,许多资源在 Web 访问和移动访问之间共享。 aspx 页面可以显示在网络上,也可以在移动应用程序中调用 WebView 。我的问题是: WebOpe
我通过调用 IEnumerable.GetEnumerator() 得到了一个枚举器,然后我称它为MoveNext()直到它返回false,然后访问它的Current属性(property)。令我惊讶
我正在尝试动态查找当前运行的函数(此函数)的名称,即 (defun my-func () (remove-hook 'some-hook this-function) (do-
阅读了短语 "The current SynchronizationContext is a property of the current thread" correct" ,我有点懵了…… 在 V
集成 IOS STRIPE TERMINAL SDK对于BBPOS Chipper 2X BT使用 swift 。我们已经开发并测试了该系统,并且运行良好。但是当我们将它交给其他国家的客户时,他们收到
当我在训练期间编写的类上实现 IEnumerable 和 IEnumerator 时,我注意到我需要为属性“Current”指定两个实现。 public class PeopleEnumerator
我原以为对实现了 IEnumerable 的空集合执行以下代码会抛出异常: var enumerator = collection.GetEnumerator(); enumerator.MoveNe
应Application.Current.Shutdown()不用作关闭 WPF 应用程序的最佳实践? 我有一个小的多窗口应用程序,“关机”似乎对我所有的退出命令都很好。但是,我被告知要始终使用 Ap
在 XPath 1.0 中,有一个函数 current() 可以派上用场,当我根据我当时所在的节点引用 XML 中其他地方的节点时。我的 XML 具有如下结构:
在 MVC 中,这两者有什么区别? 它们看起来相同,甚至返回相同的类型/类System.Web.Security.RolePrincipal,但有一些微妙之处。 例如。当针对通过 ClaimsPrin
这个问题在这里已经有了答案: What is the difference between an App and Application in c#.net? (1 个回答) 关闭 7 年前。 这两
我正在为我的团队开发一个代码生成器 (VSIX),在我与 VSIX 可扩展性框架作斗争之后,我打算使用 Roslyn 作为基础引擎。 我的代码生成器目前能够为解决方案生成一个新的 csproj,并且能
为什么 $('a.current').parent('li').addClass('current'); 和 $(this).hasClass('current')。 parent('li').add
当我使用 Xcode 调试我的 iOS 程序时,gdb 将其显示在控制台 View 上,并且没有发生任何错误。 我只想知道输出“Current language: auto; currently ob
我是一名优秀的程序员,十分优秀!