自己包装中的路线问题-Laravel 5.6 [英] Problems of routes in own package- Laravel 5.6
问题描述
我创建了一个laravel软件包,并添加了路线,视图,迁移等,并将其链接到我的项目.到目前为止,一切都是正确的,但是身份验证不起作用,我唯一要做的就是像正常的laravel项目中那样生成身份验证路由,并且我已通过以下方式将其添加到路由组中:
I have created a laravel package and I have added routes, views, migrations, etc. and I have linked it to my project. Up to here everything is correct, but authentication is not working, the only thing I have done has been to generate the authentication routes as in a normal laravel project and I have added it to the group of routes in the following way:
<?php
use Illuminate\http\Request;
//That file is the package's web.php
Route::group(['namespace'=>'myPackage\Blog\Http\Controllers', 'middleware' => 'auth'], function(){
Route::get('blog','BlogController@index')->name('blog');
Route::post('blog', 'BlogController@send');
Route::get('administrador', 'adminController@index')->name('administrador');
});
这就是我包裹的serviceProvider:
and that is my package's serviceProvider:
<?php
namespace Tetres\Blog;
use Illuminate\Support\ServiceProvider;
class BlogServiceProvider extends ServiceProvider{
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
$this->loadViewsFrom(__DIR__.'/views', 'blog');
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
}
public function register()
{
}
}
只需添加'middleware' => 'auth'
,这些路由就会停止工作,我应该怎么做的一些想法?谢谢!
simply by adding 'middleware' => 'auth'
, these routes stop working, some idea of what I should do? Thank you!
推荐答案
我遇到了同样的问题.在@lagbox上展开
I was facing the same problem. Expanding on @lagbox,
在通常表示$this->middleware("auth");
如何在控制器的__construct()
中执行此操作的示例.
An example of how you will do it in the __construct()
of your controller.
class my_controller extends Controller
{
public function __construct()
{
$this->middleware("web"); // this will solve your problem
$this->middleware("auth");
}
...
}
在您的情况下,将'web'
添加到中间件:
In your case, add 'web'
to your middleware:
//That file is the package's web.php
Route::group(['namespace'=>'myPackage\Blog\Http\Controllers', 'middleware' => ['web', 'auth']], function(){
Route::get('blog','BlogController@index')->name('blog');
Route::post('blog', 'BlogController@send');
Route::get('administrador', 'adminController@index')->name('administrador');
});
这篇关于自己包装中的路线问题-Laravel 5.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!