Peter Peter - 3 months ago 25
PHP Question

Package development - auth check doesn't work

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.

Problem



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.

A hint



I am not sure how to follow this hint

To do



Please instruct me how to make the
Auth::check()
work in the view.

Answer

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
});