php - laravel | How to replace a field in form's request? -


i using laravel 5.4 , i'm trying replace imagepath field in request (renaming uploaded image).

explanation:

when form submitted request field(request->imagepath) contains temporary location of uploaded image, moving tmp image dir while changing name ($name). request->imagepath still has old tmp image location want change request->imagepath value have new location , create user.

like so

     if($request->hasfile('imagepath'))       {             $file = input::file('imagepath');              $name = $request->name. '-'.$request->mobile_no.'.'.$file->getclientoriginalextension();               echo $name."<br>";              //tried didn't work             //$request->imagepath = $name;              $file->move(public_path().'/images/collectors', $name);              $request->merge(array('imagepath' => $name));              echo $request->imagepath."<br>";      } 

but not working, here output

 mahela-7829899075.jpg   c:\xampp\tmp\php286a.tmp 

please help

i believe merge() correct method, merge provided array existing array in parameterbag.

however, you're accessing input variables incorrectly. try using $request->input('parameter_name') instead...

therefore, code should this:

if ($request->hasfile('imagepath')) {     $file = input::file('imagepath');     $name = "{$request->input('name')}-{$request->input('mobile_no')}.{$file->getclientoriginalextension()}";      $file->move(public_path('/images/collectors'), $name);     $request->merge(['imagepath' => $name]);      echo $request->input('imagepath')."<br>"; } 

note: can pass path public_path() , concatenate you.

references
retrieving input:
https://laravel.com/docs/5.4/requests#retrieving-input
$request->merge(): https://github.com/laravel/framework/blob/5.4/src/illuminate/http/request.php#l269
public_path: https://github.com/laravel/framework/blob/5.4/src/illuminate/foundation/helpers.php#l635


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -