@if ( $currentUser)
@extends('layouts.in')
@section('content')
@else
@extends('layouts.login')
@section('content')
@endif
@stop
Because this is not working and to be honest not my favorite solution, I wanted to do this in routes.php. But I have no idea how to do this.
I want to do something like this:
Route::filter('howto', function()
{
if (Auth::check())
{
Route::get('/', [
'as' => 'home',
'uses' => 'DashController@index'
]);
}
else Route::get('/', [
'as' => 'home',
'uses' => 'PagesController@home'
]);
});
I didn't try it but I doubt that will work.
Any suggestions appreciated by me.
Your filter is actually pretty close, take the auth filter for example:
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::guest('login');
});
Here we see the auth filter checking if the user is a guest or not, and if true, the filter redirects the user to a 'login' page.
We can add filter with similar logic to achieve what you want.
Route::filter('<whatever filter name here>', function()
{
if (Auth::guest())
{
return Redirect::action('PagesController@home');
}else {
return Redirect::action('DashController@index');
}
});
Let me know if this helps.
I had the same issue and solved it using a ternary. In one view I also had to set some variables, which previously had been part of the extend, so I just moved it up.
<?php
$title = 'FAQ';
$active_menu_item = 'FAQ';
?>
@extends(Auth::user() ? 'layouts.app' : 'layouts.main')
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community