sapneshnaik's avatar

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

0 likes
2 replies
Kaustubh's avatar
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

1 like
sapneshnaik's avatar

@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 or to participate in this conversation.