Reputation: 19
Hi I have problem with auth()->user() or $request->user() in new fresh library in /vendor/myCustom/src/Middleware/aMdl.php
public function handle($request, Closure $next, $right)
{
return var_dump($request->user()); <------ Here i get NULL
if($request->user()->hasRights($right)){
return $next($request);
}
return redirect("/");
}
Here is a simple service provider
public function boot()
{
$this->loadViewsFrom(__DIR__."/views", 'aFolder');
}
/**
* Register services.
*
* @return void
*/
public function register()
{
include __DIR__."/routes.php";
$this->app->make("aCustomlib\aFolder\Controllers\aController");
}
A simple route.
Route::get("/aPath", "aCustomlib\aFolder\Controllers\aController@index");
I registered the middleware in Kernel.php
Then im just calling in __constructor in aController.php
$this->middleware('rights:aRight');
I know that names are silly named but its just an example and Im just learning.
Thanks for an answer.
PS: All these files are in /vendor folder
This happens even if I use in the __constructor(){ $this->middleware('auth')
Upvotes: 1
Views: 233
Reputation: 146201
You need to wrap your routes within the web
middleware group (starts and populates the session related data), for example:
Route::group(['middleware' => 'web'], function () {
include __DIR__."/routes.php";
});
Upvotes: 1