It all depends on what you need the data for. I have several fields where I want a specific default. This could be a filter by date, that when empty should use today. But in some other cases I explicitly want null if nothing is selected, and therefor leave out the default. So just make sure you know exactly what you expect out of each request value and set the default that fits
Is it a good practice for retrieving GET request data and set default value for it ?
Hello guys, I curious about this method to get data from request. For example
// this is a custom validator create to validate the data and the rules is write according to the retrieve data // can just ignore this one $this->validator($request->all(), $rules);
// most important is this get method $name = $request->get('name', ''); $age = $request->get('age', 0); $type = $request->get('type', 1);
You can see that they define the var with the GET data from request and set a default value for it. So my question is, is it a good practice to have a default value when you get the data and why ? How will it affect the results when I use this method ?
Please or to participate in this conversation.