Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Added ability to reference actions via an array #11300

Closed
wants to merge 2 commits into from
Closed

[5.1] Added ability to reference actions via an array #11300

wants to merge 2 commits into from

Conversation

robinvalk
Copy link

This pr adds the ability to reference actions via an array as followed:

return redirect()->action([OtherController::class => 'getIndex']);

instead of

return redirect()->action('\\' . OtherController::class . '@getIndex');

This is way cleaner and obvious in my opinion.

Also works in the routes.php

use App\Http\Controllers\OtherController;

Route::get('other', [OtherController::class => 'getIndex']);


list($class, $method) = each($action);

if (! class_exists($class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return class_exists($class);

@GrahamCampbell GrahamCampbell changed the title Added ability to reference actions via an array [5.1] Added ability to reference actions via an array Dec 11, 2015
return false;
}

list($class, $method) = each($action);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be replaced by $class = $action[0]; since $method is not used afterwards.

@robinvalk
Copy link
Author

@GrahamCampbell Should I fix the SC error or isn't it that strict?

@barryvdh
Copy link
Contributor

Looks like a good idea, so we use the ::class method in a more clean way (for importing, refactoring, ctrl+clicking etc).

Should it be [OtherController::class, 'getIndex'] instead of [OtherController::class => 'getIndex'], to be more like a regular callable array?

@barryvdh
Copy link
Contributor

Although that would conflict with actual (array) callbacks, that people could be using already.

@arrilot
Copy link
Contributor

arrilot commented Dec 11, 2015

👎
Looks like seeking for troubles imo.
There is a nice @ convention in all parts of the framework,

Route::get('other', 'OtherController@getIndex'); is so much readable.
I don't see any reason to invent another one just because of the "Let's use ::class everywhere!" trend.

If you desperately want this ctrl clicking on your routes there is an excelent phpstorm Laravel plugin providing that

@koenvdheuvel
Copy link

@arrilot I respectfully disagree.

As @barryvdh mentioned this is added functionality and the big advantage of using ::class is that you can autocomplete in a lot of IDE's and also use it as a hyperlink within your IDE. It also makes refactoring a lot easier.

@GrahamCampbell
Copy link
Member

The backslash is unneeded and should be avoided.

@GrahamCampbell
Copy link
Member

If you don't want a namespace prefix, then set it to nothing in your route service provider.

@robinvalk
Copy link
Author

This is now merged in: #24385

@robinvalk
Copy link
Author

Actual action method is merged in: #24738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants