monstajamss's avatar

Append Name to Image Upload

I am trying to save an image into the public folder with the company name in a form.

I have this in my controller

public function store(ServiceRequest $request)
    {
        
        
        $imageName = time().'.'.$request->logo_light->extension();  
     
        $request->logo_light->move(public_path('services'), $imageName);

        //Validate all request
        $serviceDetails = $request->validated();

        $services = $this->serviceRepository->createService($serviceDetails);
        
        return redirect('/system-integrators');
    }

Although this code saves inside the public folder but in the database it saves as C:\wamp\tmp\php933.tmp

I want it to save like this companyname.jpg

0 likes
9 replies
MohamedTammam's avatar

Use associative array instead with the name in it instead of $serviceDetails

$data = $request->only(['your', 'properties', 'without', 'image_name']);
$data['image_name'] = $imageName;
$services = $this->serviceRepository->createService($data);
monstajamss's avatar

@MohamedTammam i did this

 $imageName = $request->company_name.'.'.$request->logo_light->extension();  
     
        $request->logo_light->move(public_path('services'), $imageName);

        $data['logo_light'] = $imageName;

But it saved as company_name

monstajamss's avatar

@MohamedTammam No

I have a form with input name company_name so i want the image uploaded to save as the company name in the form.

For example if the company name inputted is facebook, when an image is uploaded it should save as facebook.png or facebook.jpg

MohamedTammam's avatar
Level 51

@monstajamss That should work.

 $imageName = $request->company_name.'.'.$request->logo_light->extension();  

use dd with $data before you save and see its values.

Please or to participate in this conversation.