Reputation: 2702
I have made a simple fresh Laravel 5.3 app for the purpose of developing a package. I have followed instructions from here and some modifications made in comments by user named Janis. Everything works perfectly.
Then I decided to upgrade the published view with
@if(Auth::check())
ID: {{Auth::id()}}.
@else
not logged in
@endif
The current state of the app is uploaded to Github here.
The view the check doesn't work. I always have the not logged in
.
How to make the Auth::check()
work?
In another tab of my browser I am logged correclty.
I am not sure how to follow this hint
Please instruct me how to make the Auth::check()
work in the view.
Upvotes: 0
Views: 237
Reputation: 1140
This is my structure for my package's routes in my service provider.
the only thing you have to do is, adding 'web' middleware for your routes
$routeConfig = [
'namespace' => config('banasher.controllers.namespace')."\Panel",
'prefix' => 'panel',
'as' => 'panel.',
//TODO: add middleware
'middleware' => ['web','auth']
];
$this->getRouter()->group($routeConfig, function() {
require __DIR__.'\routes\banasher.php';
});
Upvotes: 0
Reputation: 574
Since Laravel 5, any route in routes.php automatically uses the web middleware, but this does not happend with your packages routes.
To use Laravel's authentication into your package controllers and views you need to enforce the web middleware usage in to your package route.php using something like:
Route::group(['middleware' => 'web'], function () {
// your package routes here
});
Upvotes: 3