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

Resourceful URL generation #37

Closed
ShawnMcCool opened this issue Jan 14, 2013 · 16 comments
Closed

Resourceful URL generation #37

ShawnMcCool opened this issue Jan 14, 2013 · 16 comments

Comments

@ShawnMcCool
Copy link

I think that it'd be good to have the URL class able to generate resourceful links to match resourceful routing.

Maybe something like URL::resource(resource route, parameters)

Resource Routes for a user: userIndex, userCreate, userStore, userShow, userEdit, userUpdate, userDestroy

URL::resource('userCreate')
URL::resource('userEdit', $user->id)

@niallobrien
Copy link

+1. Would be awesome to have.
Perhaps URL::resource(resource route, method, parameters) would be better as the methods in our controller class are not prefixed with the resource name?
Just a thought.

@JeffreyWay
Copy link
Contributor

Shawn - do you think something like this would even be necessary, if the resourceful controller generator automatically created the named routes? I think I might prefer to stick with:

$url = URL::to_route( 'edit_user_path', array($id) );

...One less new thing to learn, and fully readable.

@ShawnMcCool
Copy link
Author

Yea, I think you're right.

On Mon, Jan 14, 2013 at 3:47 PM, Jeffrey Way [email protected]:

Shawn - do you think something like this would even be necessary, if the
resourceful controller generator automatically created the named routes? I
think I might prefer to stick with:

$url = URL::to_route( 'edit_user_path', array($id) );

...One less new thing to learn, and fully readable.


Reply to this email directly or view it on GitHubhttps://github.com//issues/37#issuecomment-12221088.

Shawn McCool | Big Name
[email protected]
heybigname.com

@niallobrien
Copy link

I agree, providing we have named routes for resources. Also means that Meido's HTML package can still be used to create links.

@taylorotwell
Copy link
Member

Coming back around to this getting ready to implement something. What do you guys think about using "dot" syntax for the route names on resourceful routes?

Like...

URL::route('user.edit', [1]);

URL::route('user'); // would point to index...

Also planning on implementing nested resources, so like:

URL::route('magazine.ads.edit', [1, 2]); // 1 being the magazine ID and 2 being the ad ID

@taylorotwell
Copy link
Member

I suggest dots because we use those throughout the framework for other things and to indicate nesting, etc.

@ShawnMcCool
Copy link
Author

I don't think that it's a bad convention. If you create a new convention for every type of thing then you're going to run out of delimiters quickly.

@niallobrien
Copy link

@taylorotwell Am I correct in assuming that we reference the controller method? Eg. URL::route('user.destroy', [1]); ? Just to clarify, routing to the action, not a named route variant.

@franzliedke
Copy link
Contributor

This looks cool. And I agree, dots feel right.

@taylorotwell
Copy link
Member

@niallobrien the name happens to match the controller action, yeah, but it's a true named route. I just thought it would be convenient if they matched the action names.

@JeffreyWay
Copy link
Contributor

I think that would work just fine. My only concern might relate to whether it confuses people. For URL::route, they'd use dot notation (preferred). For URL::action, they'd use @. Not a big deal, though.

Or, I wonder which would be considered more readable/recognizable by the community:

URL::route('user.create'); 

// or

URL::route('create_user');

Either way, I think both fit nicely.

@niallobrien
Copy link

Good point @JeffreyWay. People are used to @ representing a controller action.

@taylorotwell
Copy link
Member

Using @ could still be a tad confusing because it's not really generating anything from a controller action (even though it kinda looks that way), it's a true named route. I think we'll just stick with dots and see how it's received.

@taylorotwell
Copy link
Member

This has been implemented. Resource routes also use wildcards matching the resource names so that they may be easily used with Route::model. Also, nested resources are now supported using "dot" syntax as well:

Route::resource('magazine.photo', 'PhotoController');

@raftalks
Copy link
Contributor

@taylorotwell I noted that due to this change, I am not able to workout my api routes which is actually segmented under "api/" path for all my resources, and it is now that route::resource() no longer accept slash.
Is it possible to workout a solution as I have proposed here #181 and #170 was also taken note of this issue.

@GaryJones
Copy link

Resource routes also use wildcards matching the resource names so that they may be easily used with Route::model

Does that explain #182?

nguyen-tien-github referenced this issue in Mulodo-PHP-Laravel-Training/tuan-nguyen-laravel Oct 6, 2015
joelharkes pushed a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
…tication-endpoints

Add user + client credentials authentication endpoints
dbpolito pushed a commit to dbpolito/framework that referenced this issue Oct 1, 2019
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

No branches or pull requests

7 participants