简体   繁体   中英

how to allow only POST and GET http verb for methods of implicit controller in laravel

Suppose I have a implicit Controller like this :

class UserController extends Controller
{

    public function getShow($id)
    {
        //
    }

}

And in Routes I write this:

Route::controller('users', 'UserController');

We know that users/show responds if only user request it via GET http request.

but if I want it responds only to GET and POST (and not other methods like PUT, DELETE ,... ) How can I do that?

Of course we know that we can use any prefix for above method but it responds to all http method. like this :

class UserController extends Controller
    {

        public function anyShow($id)
        {
            //
        }

    }

If your implicit controller only contains GET and POST (prefixed) methods – no other methods will work, so there is no need to worry.

Eg. if you have:

class UserController extends Controller
{
    public function getShow($id)
    {
    }

    public function postShow($id)
    {
    }
}

Laravel will only allow 'GET /show' and 'POST /show'.

Please however note that Laravel is abandoning implicit controllers soon, because, even though they offer simplicity, implicit controllers introduce a number of disadvantages. This article has a good analysis.

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