What i'm referring to is having a route like Route::post('statuses/{id}/comments'), do you guys prefer to use the parameter from the route or a hidden field in the form (eg ) that's posting to that url?
Seems like having the hidden field is pointless, but in the Larabook series, Jeffrey used a url/route like above and he still used a hidden field to send the id while the id parameter from the route was unused. So I'm wondering if I'm missing some advantages to using a hidden field?
I understand why he had the parameter in the url, as he wanted to follow the resourceful routes pattern, but given he can access the id from the route parameter, surely there is a reason he still preferred to add a hidden field and use that to access the value instead?
He wasn't using Route:resource but he was following the same pattern just defining the routes individually IIRC. So that's why he used it I believe, to show that url pattern. But he did not use the parameter for anything, instead he retrieved the id from a hidden field on the form. I think the only advantage there was to doing it like that is it saved a line or two of code as it would automatically be in the array that Input::all() returns, rather than setting $input['id'] = $id;
Personally, I just don't like the idea of having both when only one is needed, so I want to choose one for my project. I really can't think of much difference, they can both by manipulated by the user so either way they have to be validated.
Yeah not sure what video you watched but it could be an old one or maybe he forgot about the one in the URL. Saving a line of code in PHP but gaining one in HTML (plus extra post data)...
If they're the same value, using the ID in the URL can be miles better (since you can do checking of this before it even reaches the controller). Filters can check permissions to see if they have access to that ID.
I have same doubt, I am submitting form by ajax post method and getting the resource id from the url, but i think using inspect element we can modify url , when should I use hidden field and when url parameter
Either can be modified by a user. So in the end it doesn't matter as you need to do server side checks.
One I can think of as an example is using slugs. Maybe your routes use a slug instead of an id. In that case on editing you may need to pass the id as hidden incase the slug changes. Granted it will pass the old slug but integer look ups on primary keys are faster.