php - paginate manually after paginate -


i want sort pictures , paginate them .

like has table : pic_id ,user_id

pic_id id of picture , user_id id of user liked picture.

in $sort have pic_id , count count of likes.

now, problem pictures 0 likes, not adding in $pic

any solution?

public function sort() {     $id = auth::user()->id;     $sort=db::table('likes')          ->select('pic_id',db::raw('count(pic_id) count'))          ->groupby('pic_id')          ->orderby('count','desc')          ->paginate(3);      $pic_id=collect($sort->items())->pluck('pic_id')->toarray();     $pic=picture::wherein('id',$pic_id)                  ->with('user')                 ->get();      $data=new lengthawarepaginator($pic,$sort->total(),$sort->perpage(),$sort->currentpage());     return response()->json([         'success' => true,         'data' => $data,     ]); } 


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -