Reputation: 1196
I have manage to redirect users to a different views/parts of the site based on the users credentials, say the user want to see their profile, no problem, or add a new "post".
Routes:
/admin <--- only admins no problem
/myprofile <-- only register users no problem
/admin/reports <-- only admins with certain access... no problem
foo.com/
shows a regular home page, when users login they get send to foo.com/home
there I have access to the users information, but if the user goes to foo.com/contact
I lose the users information, it shows like if the user hasn't logged in.
So the user goes to the login and get redirected to the foo.com/home
without logging in because the user is already logged in.
So in order for me to access the users information I have to add this code to ContactController.php
:
public function __construct(){
$this->middleware('auth');
}
But by doing so, any body else will have to log in or register in order to access my /contact
page and we don't want that, do we?
So how can we check if user has log in and what credentials are been use from any page on the site, and at the same time give access to regular guests.
Say we have /contact
, /services
, /products
, etc. Those pages don't require authentication yet we want to check if a user has logged in and access that information.
Upvotes: 1
Views: 156
Reputation: 14747
In the routes.php
file you need to declare each routes that need session into the web
middleware, so check if contact
route is there inside.
Route::group(['middleware' => 'web'], function(){
// contact route here
});
Upvotes: 1