Using Distinct in Laravel Fluent Using Distinct in Laravel Fluent laravel laravel

Using Distinct in Laravel Fluent


In my project I tried distinct() and groupby() too and both of them worked:

//Distinct version.Company_Customer_Product::where('Company_id', '=', $companyid)->distinct()->get(array('Customer_id'));//Goup by version.Company_Customer_Product::where('Company_id', '=', $companyid)->groupby('Customer_id')->get(array('Customer_id'));

According to this, distinct() should work in your case too, just use it with get():

Return DB::table('volunteer')   ->join('volunteer_volunteer_category', 'volunteer_volunteer_category.volunteer_id', '=', 'volunteer.id')   ->select(array('*','volunteer.id AS link_id'))   ->distinct()   ->where('is_published', '=', 1)   ->get(array('volunteer.id'));

Otherwise you don't need distinct() when you use groupby() so you could just use:

Return DB::table('volunteer')   ->join('volunteer_volunteer_category', 'volunteer_volunteer_category.volunteer_id', '=', 'volunteer.id')   ->select(array('*','volunteer.id AS link_id'))   ->group_by('volunteer.id')   ->where('is_published', '=', 1)   ->get(array('volunteer.id'));