user9334443
user9334443

Reputation:

Laravel 5.6 How to do save images correctly on storage

I want to save my images storage. But there are some errors about that.

Here is my codes in controller;

if ($request->hasFile('site_logo')) {
     $image = $request->file('site_logo');
     $realname = pathinfo($request->file('site_logo')->getClientOriginalName(), PATHINFO_FILENAME);
     $extension = $image->getClientOriginalExtension();
     $new_name = $realname."-".time().$extension;
     $image->storeAs('public/uploads', $new_name);
     $path = Storage::url($new_name);
     $settings->site_logo = $new_name;
     $settings->site_logo_path = $path;
     $settings->site_logo_alt_name = $realname;
    }

Database records;

site_logo | /tmp/phpqTLyXY
site_logo_path | /storage/1518975452-logo.png
site_logo_alt_name | logo

Questions;

1- Why site_logo can't get $new_name instead "/tmp/phpqTLyXY" ?

2- $path says "/storage/1518975452-logo.png" is image url. But When I said "project.app/storage/1518975452-logo.png" it says "Sorry, the page you are looking for could not be found." it can't found image ?

Sorry for bad english knowledge :/

Upvotes: 2

Views: 2091

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

You need to create a symlink:

php artisan storage:link

Then you'll be able to access the image with:

project.app/storage/uploads/image_name.png

Upvotes: 2

Related Questions