Ad

How To Allow Only POST And GET Http Verb For Methods Of Implicit Controller In Laravel

- 1 answer

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)
        {
            //
        }

    }
Ad

Answer

If your implicit controller only contains GET and POST (prefixed) methods – no other ixed) 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.

Ad
source: stackoverflow.com
Ad