I am a beginner in Laravel 5.
How can I remove whitespaces in validator?? i have read the documentation but there is no validator for trim(remove whitespaces).
You can use this in your request file.
$input = request()->all();
$input['url'] = trim($input['url']);
request()->replace($input);
You can also create an all()
function in your request file to update request parameters:
public function all()
{
$all = parent::all(); // $this->all();
$all['new_key'] = "new_data";
$all['old_key'] = "new_data";
return $all;
}
$data = $r->all();
foreach ($data as $key => $value) {
if($value!=""){ //If your primaryKey id is autoincrement
$data[$key] = preg_replace('/\s{2,}/',' ',$value);
}
}
$variable = new modelName($data);
$variable->save();
//Here Parameter Explaination
=> '/\s{2,}/' Pattern must write between '/ /' and \s{2,} means 2 or more than 2 spaces sholud be trim
=> ' ' second parameter is with. Means 1st parameter replace with 2nd parameter(here, one space)
=> $value is variable which is trim