Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to save path after upload in laravel storage?

I want to after uploading an image save it like this

images/blogs/1650953308.jpg

But I see this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

1650953308.jpg

I want to save like this

images/blogs/1650953308.jpg

public function store(Request $request)
{
    $fileNameService = $request->file('image') ?? null;
    if ($request->hasFile('image'))
    {
        $file = $request->file('image');
        $name = time();
        $extension = $file->getClientOriginalExtension();
        $fileNameService = $name . '.' . $extension;
        $img = Image::make($file->path());
        $img->resize(600, 300, function ($constraint) {
            $constraint->aspectRatio();
        })->save('storage/images/blogs/'.$fileNameService);
    }
    Blog::query()->create([
        'image' => $fileNameService,
    ]);
    return redirect()->route('admin.blogs.index');
}

>Solution :

Concatenate folder path with image name.

 Blog::query()->create([
        'image' => 'images/blogs/'.$fileNameService,
    ]);

It will save as images/blogs/1650953308.jpg.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading