Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5.2 how to protect route only for authenticated user

Tags:

php

laravel-5

i'm new to laravel, i had installed auth scaffold, here is the route up to now.

Route::group(['middleware' => ['web']], function () {

    Route::auth();
    Route::get('/home', 'HomeController@index');    


    Route::get('addthreadhtml', function()
    {
        return View::make('addThreadForm');
    });
    Route::post('thread/add', 'ThreadController@addthread');
    Route::get('thread/showall', 'ThreadController@showallthread');

});

i want to protect addthreadhtml from non-authenticated user access, if the user don't login, they will be redirected to another view.

How can i do that?

like image 666
hkguile Avatar asked Jan 01 '26 05:01

hkguile


1 Answers

Add the auth middleware to the route you want to protect:

Route::get('addthreadhtml', ['middleware' => 'auth', function () {
    return View::make('addThreadForm');
}]);
like image 193
Frank Martin Avatar answered Jan 03 '26 20:01

Frank Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!