How to change a field in request before creating? I am using laravel 5.4 and I'm trying to replace the imagePath field in my request (renaming the uploaded image). like so
if($request->hasFile('imagePath'))
{
$file = Input::file('imagePath');
$name = $request->name. '-'.$request->mobile_no.'.'.$file->getClientOriginalExtension();
echo $name."<br>";
//tried this didn't work
//$request->imagePath = $name;
$file->move(public_path().'/images/collectors', $name);
$request->merge(array('imagePath' => $name));
echo $request->imagePath."<br>";
}
But Its not working, Here is the output
mahela-7829899075.jpg
C:\xampp\tmp\php286A.tmp
Please Help
public function insertSellerFinantialInfo(Request $req){
$mobile_no = $req->input('mobile_no');
$file=Input::file('imagePath');
$extension = $file->getClientOriginalExtension();
$image = 'mahela-'.$mobile_no.'.'.$extension1;
$file->move(public_path('images'), $image);
echo $image;
}
I think this will solve your problem
@Kaustubh
my code correctly saves the image to required location but after that I want to change the $request-> imagePath value to the $name so that when I create the user using the request the imagePath in table will have the new image name.
Please sign in or create an account to participate in this conversation.