laravel which route or link should I use for this

2019-03-05 17:46发布

问题:

I have an xmldocument model, which I can show its profile in this way:

`public/xmldocument/4`

From this page, there are three links, which are:

add general information 

add master information

add general information

each of them is for a resource. for example:

add general information is the create of the resource general_information

add master information is the create of the resource master_information

add general information is the create of the resource general_information

But each of them must know the xmldocument id. in my case, each of them should know that they are belongs to the xmldocument = 4

My question is should I route each of them to this link

`public/xmldocument/4/generalinformation/create` ?

or to this link

`public/generalinformation/create` ?

in the second case, I have to pass the xmldocument id, but can I really do that using the a tag?

回答1:

as Oni said, its something related to your business logic, so there are no way as the best way or a way which is better than this way, its all back to you ..

now about the second question sending the id of the document when using

public/generalinformation/create

in general you should append the id of the document to the link so that you can handle it in the next page as a tag will only provide _GET values, but in Laravel you can use slug for example to solve this issue so your link can be something like

public/xml_doc_slug/generalinformation/create

so this way you query your database for the slug and get the id of the xml document.

In my opinion, try to make your URL's as simple as you can so that you can deal with it later.