Support the ongoing development of Laravel.io →
Configuration Authentication

So I'm a little bit new to Laravel, and slightly new to MVC frameworks. I've learned a little bit of CakePHP and Rails but haven't yet put out a full app. I'm liking what I see with Laravel and I'm using it for my current small project.

I am attempting to have the root path do one of two things: If the user is a guest (not logged in), show a static "welcome"/"landing" page. If they ARE logged in, instead show the main "feed" of the application. I'd prefer both of these be in separate controllers. One would handle all static pages, the other handles the feed and adding new information to the feed.

Is there a way to keep this logic in the respective controllers, but keep the route as '/' and use the appropriate controller? I'd prefer not to use a redirect and end up with "/home" or "/feed"

Last updated 3 years ago.
0

Hmmm,

In controller

	public function __construct()
	{
		$this->middleware('auth');
		$this->middleware('guest');
	}

in your middleware:

		if ($this->auth->guest())
		{
			if ($request->ajax())
			{
				return response('Unauthorized.', 401);
			}
			else
			{
				if ( Config::get('general.require_login') === true) {
					return redirect()->guest('auth/login');
				}
				return redirect()->guest('/');
			}
		}

I'd take a look at a few starter / bootstrap apps that people have put up on github. https://github.com/bestmomo/laravel5-example

I learned a lot by looking at other people's solutions.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.