Reputation: 5782
I am trying to get the 9 most recent images from a user, however, I also would like to exclude the image with an id of $id. What I currently have gets the last 9 images, which might include the image with id
of $id
. I would like to somehow not include the image with id
of $id
in the result.
public function specificImage($id){
$image = Image::find($id);
$authorId = $image->user_id;
$recentImages = Image::where('parent_id', NULL)->where('user_id', $authorId)->orderBy('created_at', 'desc')->limit(9)->get();
}
Upvotes: 0
Views: 145
Reputation: 10254
Just use a WHERE
clause:
Image::where('id', '!=', $id)->/* ... */->get()
Upvotes: 4
Reputation: 1891
This should work ?
$recentImages = Image::where('parent_id', NULL)->where('user_id', $authorId)->whereNotIn('id', [$id])->orderBy('created_at', 'desc')->limit(9)->get();
Upvotes: 1