Witam. Poprzez formatkę zapisuję sobie obrazki w bazie:
welcome.blade.php
<div class="custom-file">
<input type="file" name="cover" class="custom-file-input{{ $errors->has('cover') ? ' is-invalid' : '' }}">
<label class="custom-file-label">Wybierz obraz</label>
@if ($errors->has('cover'))
<div class="invalid-feedback">
<strong>{{ $errors->first('cover') }}</strong>
</div>
@endif
</div>
Mam pole w tabeli:
public function up()
{
Schema::create('scholarships', function (Blueprint $table) {
$table->increments('id');
$table->string('imgcover');
$table->timestamps();
});
}
Zapisuję w bazie:
ScholarshipsController.php
public function store (Request $request)
{
$request->validate([
'cover' => 'required|image'
]);
$movie = Scholarship::create([
'imgcover' => $request->file('cover')->store('covers')
]);
return redirect()->route('home');
}
I próbuję (co jest głównym celem) wyświetlić zapisane obrazy i pobrać je za pomocą linku:
welcome.blade.php
@foreach ($scholarships as $scholarship)
{{ $scholarship->imgcover }}
<img class="card-img-top" src="storage/app/{{ $scholarship->imgcover }}" alt="alt">
<a href="/storage/app/{{ $scholarship->imgcover }}" download> POBIERZ </a>
<a href="/app/{{ $scholarship->imgcover }}" download> POBIERZ 2 </a>
<a href="/{{ $scholarship->imgcover }}" download> POBIERZ 3 </a>
@endforeach
Jak widzicie próbuję różnych ścieżek, ale cały czas obrazy ani nie chcą się wyświetlić, ani linki do pobrania nie działają. Obrazy zapisują się poprawnie w /storage/app/covers, w bazie w polu $scholarship->imgcover zapisują się nazwy obrazów (typu nXnE3bsnrpPQtt9QoXLDWCJiM8DEdZdCz3sGNoKm.png), więc ścieżka powinna wyglądać następująco: /storage/app/covers/nXnE3bsnrpPQtt9QoXLDWCJiM8DEdZdCz3sGNoKm.png. Próbuję ją różnie ująć jak wyżej, ale ciągle nic.