Laravel routes controller action declaration

I’ve just installed Laravel 8 besides Laravel Breeze and in auth.php file in the routes directory, I see how we should import the namespace the of the controllers.

As you see you for declaration the store action, we have to put a bracket around the controller and the action like below

It means in Laravel 8 and above we are passing an array as the second argument for the post() method.

This is for the case that in PasswordResetLinkController controller we have more than one method.

If we have one and only one method and it is __invoke(), it is obvious that we can use the same format like above as you can see in auth.php file :

But the following format also works fine:

As you see we don’t mention the name of the method (here __invoke()) in the Rout Facade. and also removed the brackets around the controller declaration.

This is because of we are using __invoke() that is a magic method in php and is called when a script tries to call an object as a function. In our case, the object is an instance of the VerifyEmailController::class.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store