Coder Social home page Coder Social logo

Resourceful URL generation about framework HOT 16 CLOSED

laravel avatar laravel commented on May 5, 2024
Resourceful URL generation

from framework.

Comments (16)

niallobrien avatar niallobrien commented on May 5, 2024

+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.

from framework.

JeffreyWay avatar JeffreyWay commented on May 5, 2024

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.

from framework.

ShawnMcCool avatar ShawnMcCool commented on May 5, 2024

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

from framework.

niallobrien avatar niallobrien commented on May 5, 2024

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

from framework.

taylorotwell avatar taylorotwell commented on May 5, 2024

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

from framework.

taylorotwell avatar taylorotwell commented on May 5, 2024

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

from framework.

ShawnMcCool avatar ShawnMcCool commented on May 5, 2024

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.

from framework.

niallobrien avatar niallobrien commented on May 5, 2024

@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.

from framework.

franzliedke avatar franzliedke commented on May 5, 2024

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

from framework.

taylorotwell avatar taylorotwell commented on May 5, 2024

@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.

from framework.

JeffreyWay avatar JeffreyWay commented on May 5, 2024

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.

from framework.

niallobrien avatar niallobrien commented on May 5, 2024

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

from framework.

taylorotwell avatar taylorotwell commented on May 5, 2024

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.

from framework.

taylorotwell avatar taylorotwell commented on May 5, 2024

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');

from framework.

raftalks avatar raftalks commented on May 5, 2024

@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.

from framework.

GaryJones avatar GaryJones commented on May 5, 2024

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

Does that explain #182?

from framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.