如何在 Laravel 5 中使用哨兵?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28538577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use sentry with laravel 5?
提问by Ogie Sado
I have tried installing sentry in laravel 5 but it doesn't work. I would like to know if anyone has done it and how to do it.
我曾尝试在 Laravel 5 中安装哨兵,但它不起作用。我想知道是否有人做过它以及如何做。
Update: I used the instructions for Laravel 4.
更新:我使用了 Laravel 4 的说明。
回答by scrfix
I have this working.
我有这个工作。
There is no official support right now for Sentry in L5. They state this right on their website. They are working on it however.
Add the following to your composer.json file in the require section.
"cartalyst/sentry": "dev-feature/laravel-5", "illuminate/html": "~5.0"
目前没有官方支持 L5 中的 Sentry。他们在他们的网站上声明了这一权利。然而,他们正在努力。
将以下内容添加到您的 composer.json 文件中的 require 部分。
"cartalyst/sentry": "dev-feature/laravel-5", "illuminate/html": "~5.0"
Add the following to the autoload section.
将以下内容添加到自动加载部分。
"app/Http/Controllers",
It should look something like:
它应该看起来像:
"require": {
"laravel/framework": "5.0.*",
"cartalyst/sentry": "dev-feature/laravel-5",
"illuminate/html": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database",
"app/Classes",
"app/Http/Controllers",
"app/Models"
(Presuming linux with no aliases) Run php composer.phar dump-autoloadthen php composer.phar update
Follow the instructions on the following page to convert your files from 4.2 to 5.0: http://laravel.com/docs/master/upgrade#upgrade-5.0
If you are using HTML Facade for FORMS then change {{{ }}} or {{ }} for the FORM's to {!! !!} because L5 escapes all output from {{{ }}} and {{ }}. If you want raw output you must use {!! !!}.
When you move your redirect check to the boot method as per the instructions in #4 then add the following to the top of the RouteServiceProvider.php
use Cartalyst\Sentry\Facades\Laravel\Sentry;
(假设 linux 没有别名)运行php composer.phar dump-autoload然后php composer.phar update
按照以下页面上的说明将文件从 4.2 转换为 5.0:http: //laravel.com/docs/master/upgrade#upgrade-5.0
如果您使用 HTML Facade for FORMS 然后将表单的 {{{ }}} 或 {{ }} 更改为 {!! !!} 因为 L5 转义了 {{{ }}} 和 {{ }} 的所有输出。如果你想要原始输出,你必须使用 {!! !!}。
当您按照 #4 中的说明将重定向检查移动到引导方法时,将以下内容添加到 RouteServiceProvider.php 的顶部
使用 Cartalyst\Sentry\Facades\Laravel\Sentry;
The boot method should look something like:
引导方法应该类似于:
public function boot(Router $router)
{
parent::boot($router);
// Check if someone is already logged in
Route::filter('members_auth',function(){
//If already logged in go to dashboard or else login
if(!Sentry::check()){
return Redirect::to('/login');
}
});
//
}
UPDATE 02-26-15
更新 02-26-15
- Do not run the command php artisan optimizeas it will break sentry. I could not figure out what was wrong after I ran this but thought it probably has to be with the compiled.php file so I ran php artisan optimize --forceand that fixed whatever the issue was.
- 不要运行命令php artisan optimize因为它会破坏哨兵。运行此程序后,我无法弄清楚出了什么问题,但认为它可能与compiled.php 文件有关,因此我运行了php artisan optimize --force并解决了任何问题。
Hope it helps.
希望能帮助到你。
Wayne Leiser, I.T. Director
Wayne Leiser,IT 总监
B2B I.T. Solutions
B2B IT 解决方案
** Update 29-03-2018 ** Sentry now supports Laravel 5.x
** 29-03-2018更新 ** Sentry 现在支持 Laravel 5.x
回答by Jeremy Schaffer
I haven't personally installed it, but I know it's compatible. https://medium.com/@Cartalyst/laravel-5-support-4c11e01c3337
我没有亲自安装它,但我知道它是兼容的。 https://medium.com/@Cartalyst/laravel-5-support-4c11e01c3337
The installation instructions do not have specific Laravel5 information though it should be identical to L4 pending you pull in the correct branch. Assuming you are using composer you can do this by requiring "cartalyst/sentry": "dev-feature/laravel-5"
in your composer.json.
安装说明没有特定的 Laravel5 信息,但在您拉入正确的分支之前,它应该与 L4 相同。假设您正在使用作曲家,您可以通过"cartalyst/sentry": "dev-feature/laravel-5"
在 composer.json 中要求来做到这一点。
Follow the rest of the L4 installation (add to providers and aliases array) and information except remember app.php is no longer in app/config/app.php
but in config/app.php
按照 L4 安装的其余部分(添加到 providers 和 aliases 数组)和信息,除了记住 app.php 不再在app/config/app.php
但在config/app.php
If things are still not working for you, be sure to update your question with at least some information...
如果事情仍然不适合您,请务必使用至少一些信息更新您的问题......
回答by jamlee
bootstarpCms use both laravel5 and sentry ,so you can read the source code to learn .here https://github.com/BootstrapCMS/CMS
bootstarpCms 同时使用 laravel5 和 sentry,所以你可以阅读源代码来学习。这里https://github.com/BootstrapCMS/CMS
回答by star18bit
Try Sentinel: https://github.com/rydurham/Sentinel
尝试哨兵:https: //github.com/rydurham/Sentinel
add to composer
添加到作曲家
composer require rydurham/sentinel
In config/app.php
在 config/app.php
'providers' => array(
...
'Sentinel\SentinelServiceProvider',
...
)
In app/Http/Kernel.php
在 app/Http/Kernel.php
protected $routeMiddleware = [
// ..
'sentry.auth' => 'Sentinel\Middleware\SentryAuth',
'sentry.admin' => 'Sentinel\Middleware\SentryAdminAccess',
];
then
然后
publish config:
发布配置:
php artisan sentinel:publish
run migrations:
运行迁移:
php artisan migrate
run seeder:
运行播种机:
php artisan db:seed --class=SentinelDatabaseSeeder
add home route in app/routes.php
在 app/routes.php 中添加家庭路线
Route::get('/', array('as' => 'home', function()
{
return View::make('home');
}));
all done, go to myapp.dev/login
全部完成,转到 myapp.dev/login