php - How to shuffle and paginate data with laravel

one text

I want to shuffle and paginate data in laravel.

when I use this code :

`$questions = Question::where("exam_id",$exam->id)->shuffle()->paginate(1);`

gives me this error : BadMethodCallException Call to undefined method Illuminate\Database\Eloquent\Builder::shuffle() and when I use this code:

$questions = Question::where("exam_id",$exam->id)->paginate(1)->shuffle();

in dd($questions = Question::where("exam_id",$exam->id)->paginate(1)->shuffle());gives me a collection that has the first item and other items don't exist. And there is also no paging information.And when I don't use dd() gives me this error : Method Illuminate\Database\Eloquent\Collection::links does not exist. While I use $questions->links() in the view. When I use this code :

$questions = Question::where("exam_id",$exam->id)->get()->shuffle()->paginate(1);

Gives me this error : Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

And when I use this code :

$questions = Question::where("exam_id",$exam->id)->inRandomOrder()->paginate(1);

It works, but the data is repeated on later pages. For example, the data on the first page may be repeated on page seven or other pages.

In fact, I want the data to be sorted by random And then paginated so that when a data is loaded on one page not repeated on subsequent pages.

please help me!!Thanks

Source