Have you try with below code,
php artisan storage:link
it saves into the storage/app directory, so when I create a symlink things dont work, what am I missing?
shouldnt it save in the storage/app/public directory?
Have you try with below code,
php artisan storage:link
yes i did that but it create a symink from public/storage to storage/app/public
but the files are being saved in storage/app which according to the docs should be saving in storage/app/public
It will create the correct storage path on your system and then you can access by below.
<img href="{{asset('public/yourimage.jpg')}}" />
Can you show your save function in your controller and your index.blade.php?
public function store($id)
{
// dd(request()->all());
$path = request()->file('asset')->store('public');
$asset = new Asset();
$asset->project_id = $id;
$asset->title = request('title');
$asset->file = $path;
$asset->downloaded = 0;
$asset->save();
return back();
}
as you see i have to tell laravel to store in public folder or else it doesnt
@foreach ($project->assets as $asset)
<li>{{ $asset->title }}, <a href="{{ asset($asset->file) }}">download</a>, Downloaded {{ $asset->downloaded }} time(s)</li>
@endforeach
and the url i get is this, which is wrong
http://127.0.0.1:8000/public/kMpIp6i0xeUMLfbweoI2nBjQ40sOX18bWswW66Hy.jpeg
this should work if the file is saved in storage/app/public
<a href="{{ asset('storage/'.$asset->file) }}">
check your filesystem config as well
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
@edoc how are you Edoc?
I don't want to save files in storage/app/public.
I want to save them in my public/images
Please help me improve this code
public function store(Request $request)
{
$new_book = new \App\Book;
$new_book->title = $request->get('title');
$new_book->description = $request->get('description');
$new_book->author = $request->get('author');
$new_book->publisher = $request->get('publisher');
$new_book->price = $request->get('price');
$new_book->stock = $request->get('stock');
$cover = $request->file('cover');
if($cover){
$cover_path = $cover->store('book-covers', 'public');
$new_book->cover = $cover_path;
}
$new_book->slug = str_slug($request->get('title'));
$new_book->created_by = \Auth::user()->id;
$new_book->save();
$new_book->categories()->attach($request->get('categories'));
if($request->get('save_action') == 'PUBLISH'){
return redirect()
->route('admin.books.create')
->with('status', 'Book successfully saved and published');
} else {
return redirect()
->route('admin.books.create')
->with('status', 'Book saved as draft');
}
}
i want to display them like so
src={{asset('/images/' . $book->image)}}"
``
@helpmyworld start your own question
@EDOC - filesystem config looks the same as yours, i did not mess with it
this is my code
$path = request()->file('asset')->store('assets');
this should save in storage/app/public/assets
but it saves in storage/app/assets
for the life of me I dont know why
can you try this @michalis
//public disk
$path = request()->file('asset')->store('assets', 'public');
Worked for me to.
@EDOC - ok this worked and I dont understand why it worked, did i not read the documentation properly?
i guess you forgot to set the default file driver so just add this to your .env
FILESYSTEM_DRIVER=public
@edoc this worked. Thanks
@EDOC - this wasnt in the documentation either I think, it just an overwhelming feeling trying to learn laravel when you cant trust the docs
when you check config/filesystem you can see this piece of code
'default' => env('FILESYSTEM_DRIVER', 'local'),
this sets the default driver from the environmental variable FILESYSTEM_DRIVER.
In your case, you set FILESYSTEM_DRIVER=public in .env right? so your default driver is set to public. And when you store images Laravel uses the config for the public disk from config/filesystem
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Even If code in the config/filesystem is 'default' => env('FILESYSTEM_DRIVER', 'public'),
And you set FILESYSTEM_DRIVER=local in .env
Files still gets stored to 'local' So change the FILESYSTEM_DRIVER=public in .env
or
delete the FILESYSTEM_DRIVER=local in .env and set 'default' => env('FILESYSTEM_DRIVER', 'public'), in config/filesystem
For my case you go on public folder and you delete storage folder afert it you do php artisan storage:link
@maxghis Thanks for comment , it worked! I spend my hours...
Hi, to solve this issue just change FILESYSTEM_DISK=local into FILESYSTEM_DISK=public in your .env file.
Please or to participate in this conversation.