Why Laravel Request object is replacing spaces with underscores on my form names? -


i have form posting variables containing spaces in names

e.g.

i perform ajax request , can see in chrome inspector name correctly passed "with blank space)

in api.php:

route::post('/user', 'usercontroller@get'); 

usercontroller

function get(request $request) {     dd($request->input('name surname')); //display null     dd($request->all()); //i notice key's changed name_surname  } 

taken can't change names because have contain spaces (bad practice? ok has that):

how can avoid spaces replaced? (maybe without have manipulate request->all() returned array keys hand....)

short answer don't believe there such way.

you can map response bit of string replace though:

$data = $request->all()->mapwithkeys(function($item, $key) {     return [str_replace("_", " ", $key) => $item]; }); 

if it's want apply across board, possible rig middleware apply requests.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -