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"
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community