And the view? Welcome to the forum :)
Get only the clicked image to display, and not all of them
0
Yo everyone!
I'm actually working on a lil' project to learn laravel and here is the thing I struggle to achieve : I want the image I click on to be displayed in a view, but not all of my images (my images are stored in a database).
I think the code is pretty simple, I'll share it with you :
the controller I use:
<?php
namespace App\Http\Controllers;
use App\Models\Images;
use Illuminate\Support\Facades\DB;
class ShowAdults extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$query = DB::table('images')->where('type', 'F');
$images = $query->orWhere('type', 'M')->get();
return view('showimages.chiens',compact('images'));
}
/**
* Display the specified resource.
*
* @param \App\Models\Images $images
* @return \Illuminate\Http\Response
*/
public function show(Images $images)
{
$images = DB::table('images')->select('*')->get();
return view('showimages.displaydog',compact('images'));
}
}
And the part of the view that's displaying the images:
@foreach($images as $image)
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
{{ $image->name }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Details:</strong>
{{ $image->detail }}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<img src="/image/{{ $image->image }}" width="500px">
</div>
</div>
</div>
@endforeach
Now, I know this logic is supposed to display all of the images I stored in my DB, but let's say I'm sharing it like that because all the others methods that I tried were... chaotic lol.
Do you guys know how I can change the logic in my loop so when I click on my image it displays the one I clicked instead of all the stored images?
Thanks a lot for your time, and sorry in advance cause even to me, it seems dumb that I can't find it after hours of searching, I think I need to know how to search things better ^^'.
I know I could use something like {{ $image[0]->name }} but I want it to be dynamic so every image getting uploaded would be ready to be clicked on.
Don't hesitate to ask me for more bits of code if needed, I can share without any problem.
@SepulcherZ Yeah that is what the href here does :) Notice how I set the $image->id as part of the url
<a href="/displaydog/{{ $image->id }}" >
<img src="/image/{{ $image->image }}" width="500px">
</a>
Please or to participate in this conversation.