Nathileo's avatar

Get Image File Extension when storing image using storeAs

Hi everyone. I'm stuck here. I am uploading image to storage folder and saving the image path+filename to database. I want the filename to have the image extension but I can't seem to get it. I have used getClientOriginalExtension() but it gave an error. Please help me out. Thanks Here is my code:

$food = Food::create([
    'name' => $request->input('name'),
    'image' => $request->file('image')->storeAs('foods', $request->input('name'))
]);     

Please, how do I also resize it before uploading to storage folder.

0 likes
2 replies
Nathileo's avatar

I tried this code and it worked.

$food = Food::create([
    'name' => $request->input('name'),
    'image' => $request->file('image')->storeAs('foods', $request->input('name').'.jpg')
]);

Could anyone give me a better approach instead of manually assigning a file extension.

1 like

Please or to participate in this conversation.