在Laravel 4倍验证会话 [英] Multiple Auth sessions in Laravel 4

查看:171
本文介绍了在Laravel 4倍验证会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在上的项目在管理控制台和正常前端被分割。
正面和后端处于同一Laravel实例

The project I'm currently working on is split up in an admin console and the normal frontend. Both front and backend are in the same Laravel instance.

在前端我试图创建一个用户登录系统,工程专供前端。它采用了不同的表和型号,它有不同的关系,oposed到用户模型为admin。

In the frontend I'm trying to create a user login system that works exclusively for the frontend. It uses a different table and model and it has different relations as oposed to the User model for the admin.

我想不通的是使用Laravel验证类两个系统的一种方式。从逻辑上验证使用一个单一的配置文件,并且更重要的是,一个会话名称。

What I can't figure out is a way to use the Laravel Auth class for both systems. Logically Auth uses one single config file, and more to the point, one session name.

这已经提出的一种解决方案是不使用不同的表和模型,并使用某种形式的访问控制列表的区别。但我不喜欢这样的混合前端和后端的想法。特别是因为这将意味着我会突然有给Admin用户模型中的所有字段和关系previously独特的前端用户。

One solution that has been brought forward is not to use a different table and model and use some form of acl for the distinction. But I don't like the idea of mixing frontend and backend in this way. Especially because it would mean I'd suddenly have to give the admin User model all the fields and relations previously unique to the frontend user.

它只是似乎没有做事情的正确方法。我可以切换到不同的认证系统或单独的管理员成包与它自己的configs但该项目的范围不允许这样费时的变化。

It just doesn't seem the right way to do things. I could switch to a different authentication system or seperate the admin into a package with its own configs but the scope of the project doesn't allow for such timeconsuming changes.

我欢迎任何的想法是,你可以提供。

I'd welcome any idea's you could provide.

推荐答案

这是我最近遇到一个太大的问题。整个单独的环境不是很容易,尤其是如果你已经有了开发和生产环境。

This is a problem that I encountered recently too. The whole separate environment wasn't very easy, especially if you already have development and production environments.

我也不过花一些时间来创建一个包来解决这个问题,你可以找到在 https://github.com/ollieread/ multiauth 。包本身基本上是验证一个工厂类,允许你使用它的多个实例,让你访问它,像这样:

I did however spend some time creating a package to solve this problem, which you can find at https://github.com/ollieread/multiauth. The package itself is essentially a factory class for Auth, that allows you to use multiple instances of it, so you access it like so:

Auth::admin()->check();
Auth::user()->check();
Auth::whatever()->check();

我希望包可以帮助你或其他人寻求这种做法。

I hope the package helps you or anyone else looking for this approach.

这篇关于在Laravel 4倍验证会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆