'Select Distinct row in Laravel Eloquent

I am using Laravel 8. I have two tables album and images, Images belongs to an album. I want just to display images but the ones with distinct album_id. I am trying to achieve it without success.

 public function index(){
   $images=albumImages::distinct('album_id')->pluck('album_id','path');
    dd($images);
    return view('gallery',compact('images'));
   }

This is the output

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source