File: /Modules/News/Http/routes.php
Route::group([
'namespace' => 'Modules\News\Http\Controllers\Admin',
'prefix' => 'admin',
'as' => 'admin.',
'middleware' => ['auth', 'force_locale']
], function () {
Route::get('/news', ['as' => 'news.index', function () {
dd(123);
}]);
});
In main route if I check Auth::check() (user logged in) it return true, in module/routes it always false. Where is the my mistake?
My custom 'force_locale' middleware (in app/http/middlewre/..) work fine.
Possibly the session / middleware haven't ran yet when the route file is loaded.
Middleware ran but Auth::check() always false!
If it's true in your controller it's something to do with your setup.
@nWidart it's true in /app/Http/Controllers but false in /Modules/Http/Controllers. All other functionality of Module package work fine.
# routes/web.php
...
Route::get('/', function () {
dd(Auth::check()); # return true
return view('home');
});
...
# Modules/News/Http/routes.php
...
Route::get('/news', ['as' => 'news.index', function () {
dd(Auth::check()); # return false
}]);
...
Module News was enabled
Maybe someone can check this in issue in self code?
In Modules/News/Http/Controllers/NewsController.php Auth::check(); return true.
Can't understand why 'auth' middleware return false
In this way middleware 'auth' work:
Route::group(['middleware' => 'web', 'prefix' => 'news', 'namespace' => 'Modules\News\Http\Controllers'], function()
{
Route::get('/', 'NewsController@index')->name('admin.news.index')->middleware('auth');
});
In this dosen't:
Route::group(['middleware' => 'auth', 'prefix' => 'news', 'namespace' => 'Modules\News\Http\Controllers'], function()
{
Route::get('/', 'NewsController@index')->name('admin.news.index');
});
Finally I found the problem. In documentation:
Out of the box, the web middleware group is automatically applied to your routes/web.php file by the RouteServiceProvider.
In web middleware start sessions and if I add 'web' moddleware to my module routes group all work fine:
# Modules/News/Http/routes.php
Route::group(['middleware' => ['web','auth'], 'prefix' => 'news', 'namespace' => 'Modules\News\Http\Controllers'], function()
{
Route::get('/', 'NewsController@index')->name('admin.news.index');
});
@elephantux i just wanna thank you veeery mush. this problem make me headache for 2 day. and it finally solved now T^T /
Most helpful comment
Finally I found the problem. In documentation:
In web middleware start sessions and if I add 'web' moddleware to my module routes group all work fine: