add-remove input into laravel request object

882 0 0 0

Last Updated : 2024-04-26 15:38:43

add or remove field inputs to request object or get specific elements

To add new input :
$request->request->add(['key' => value]);
Ex: to add user id do the following:
$request->request->add(['user_id' => Auth::user()->id]);


$request->request->add(['key' => value]); 
Ex: to add user id do the following:
$request->request->add(['user_id' => Auth::user()->id]);
$request->request->add(['user_id' => Auth::user()->id]);



To remove input :


$request->except(['fieldnameYouDontWant1', 'fieldnameYouDontWant2', 'fieldnameYouDontWant3']);
Ex: to rempve the token:
$inputs = $request->except(['_token']);



To get specific fields:


$request->only(['fieldname1', 'fieldname2', 'fieldname3']);

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .