Onyx
Onyx

Reputation: 5772

How to get the image information based on the image id which I already have with Eloquent?

When I click on a certain image, I send the user to :

<a href='/image/{{ $image->id }}'>

The route that handles this is:

Route::get('/image/{id}', 'PagesController@specificImage')->name('specificImage');

This function should get the information of the image with that id and pass it to a view. Unfortunately, I am not sure how to get the information of the image with id of $imageId.

public function specificImage($id) {
    $imageId = $id;
}

Upvotes: 2

Views: 157

Answers (2)

Joel Hinz
Joel Hinz

Reputation: 25374

Actually, you don't even need to look it up if you use typehinting:

public function specificImage(Image $image){
    // $image will now contain the image you're looking for
}

Upvotes: 1

Sohel0415
Sohel0415

Reputation: 9853

Assuming your model name for image table is Image -

$image = Image::find($imageId);

Upvotes: 1

Related Questions