Support the ongoing development of Laravel.io →
Authentication Session Views
Last updated 2 years ago.
0

In order to see a different page, I usually use a route like this.

Route::get('/',function(){
    if(Auth::guest()){
        return View::make('login');
    }
    return View::make('my_page');
});
Last updated 2 years ago.
0

Hum...like @moinescumihai said, you should do the Route way, your way is kind off defeating the purpose of MVC architecture.

Last updated 2 years ago.
0

Yes, you both are right, but here I want to handle back button scenario after login. The problem is that I have tried the following : Inside Controller

public function create() {
    if(!(Auth::guest())){ 
        return Redirect::intended('/'); 
    }else{
        return View::make('sessions.create');
    }
}

Its working fine. But after login if i click back button in browser it returns back to Login Form. Its really looking bad. Using :

header('location : somelocation.php');

I can achieve that but I want to use Laravel feature if any.

Last updated 2 years ago.
0

In my understanding, your problem is like this:

You have a login page and want it displayed only if the user is not logged in. You can achieve that using the code I gave you

But, to my knowledge, the back button in your browser will redirect you to the same page, with the same content. It's independent from your app.

As you said, using header('location : somelocation.php'); you "tricked" it

You can also do the same trick using laravel

Lets' say your login/post login page = 'testing'

Try using this:

Route::get('/,',function(){
    return Redirect::to('testing');
});
Route::get('testing',function(){
    if(Auth::guest()){
        return View::make('login');
    }
    return View::make('my_page');
});

It's not pleasant but I guess will do the trick. In my opinion you should just stick to

Route::get('/',function(){
    if(Auth::guest()){
        return View::make('login');
    }
    return View::make('my_page');
});
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

infvarun infvarun Joined 23 Nov 2014

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.

© 2024 Laravel.io - All rights reserved.