php - Laravel symbolic link to storage and show the pictures -
in storage have /projects/(nameofproject - not same)/header.jpg , have /projects/(nameofproject - not same)/home.png.
how can show them in view?
i explain bit more. in past, have projects on /public/assets/img/projects , dynamically.
my function create new projects , save images this:
public function storeproject(request $request) { $project = new project(); $project->slug = $request->input("slug"); $project->position = $request->input("position"); $project->public = $request->input("public"); $project->pathheader = $request->file('pathheader'); $project->pathhome = $request->file('pathhome'); \storage::disk('projects')->makedirectory($project->slug); \storage::disk('projects')->putfileas($project->slug,$project->pathheader,'header.png'); \storage::disk('projects')->putfileas($project->slug,$project->pathhome,'home.png'); $project->save(); return redirect('/admin/projects'); }
the images of projects in past show this: (i pass view variable $project)
<p class="lead"><img src="/assets/img/projects/{{$project->slug}}/header.jpg" width="50%" >header</p> <p class="lead"><img src="/assets/img/projects/{{$project->slug}}/home.jpg" width="50%">home</p>
how show images of storage folder?
edit
filesystems.php code:
'projects' => [ 'driver' => 'local', 'root' => storage_path() . '/projects', 'visibility' => 'public', ],
view looking now:
@if (storage::disk('projects')->has($project->slug)) <img src="{{ asset('storage/projects/'.$project- >slug.'/header.jpg') }}" width="50%" > @else <p class="lead"><img src="/assets/img/projects/{{$project- >slug}}/header.jpg" width="50%" >header</p> @endif
i make:
php artisan storage:link
url of image: http://url.loc/storage/projects/hola-que-tal/header.jpg (not show it).
the easiest solution use public disk. if ran php artisan storage:link
command can use following code:
\storage::disk('public')->makedirectory($project->slug); \storage::disk('public')->putfileas($project->slug, $project->pathheader, 'header.png'); \storage::disk('public')->putfileas($project->slug, $project->pathhome, 'home.png');
and html:
<p class="lead"><img src="{{ asset('storage/projects/'.$project->slug.'/header.jpg') }}" width="50%" >header</p> <p class="lead"><img ssrc="{{ asset('storage/projects/'.$project->slug.'/home.jpg') }} width="50%">home</p>
an example config in config/filesystems.php
:
'public' => [ 'driver' => 'local', 'root' => storage_path('app/public/projects'), 'url' => env('app_url').'/storage', 'visibility' => 'public', ],
of course can edit projects
disk has correct root
. i'm not sure how config looks projects
disk.
Comments
Post a Comment