Modify request data before validation in Laravel 5:
1. Replace All request data
Use replace() function to change all requested data with given data
For example
$request contains first_name, last_name field.
and we want to create one filed name with combination of first_name and last_name
$newRequest = array('name'=>$request->first_name.$request->last_name);
$request->replace($newRequest);
now $request contains name field.
2. Modify Request field data.
Use merege() function to modify requested data with given data
For Example
$request contains name field with null value .
and we want to change null to empty string.
$newRequest = array('name' => '');
$request->merge($newRequest);
Thanks
1. Replace All request data
Use replace() function to change all requested data with given data
For example
$request contains first_name, last_name field.
and we want to create one filed name with combination of first_name and last_name
$newRequest = array('name'=>$request->first_name.$request->last_name);
$request->replace($newRequest);
now $request contains name field.
2. Modify Request field data.
Use merege() function to modify requested data with given data
For Example
$request contains name field with null value .
and we want to change null to empty string.
$newRequest = array('name' => '');
$request->merge($newRequest);
Thanks
No comments:
Post a Comment