简体   繁体   中英

Protecting methods using Laravel 5 Auth

I have a bunch of controllers. One of them is ArticleController . I want the method postCreateArticle() method to require the user to be authenticated.

In the documentation, I figured you can use the auth middleware, like so:

Route::get('profile', ['middleware' => 'auth', function()
{
    // Only authenticated users may enter...
}]);

However, I am registering my controllers in the routes :

Route::controller('articles', 'ArticleController');

How do I protect the postCreateArticle() method, without doing it inside the method?

在构造函数中,您应该能够:

$this->middleware('auth', ['only' => 'postCreateArticle'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM