'how to use paginate in laravel

The following retrieves json data from the api and passed it to the loop to list and display the data gathered

Controller code:

class pagesController extends Controller
{
    public function index()
    {
        $data = Http::get('http://universities.hipolabs.com/search?country=australia')
            ->json();
        
        return view('pages.allpage', ['data' => $data]);
    }
}

I want to paginate it and only show 10 items each list

HTML code:

@foreach($data as $item)

<div id ="example1">
    <h3>{{$item['name']}}</h3>
    <p>{{$item['country']}}</p>

     <form action="{{($item['web_pages'])[0]}}" target="_blank">
          <button class= "button glow-button" target="_blank">visit</button> 
     </form>
</div>
@endforeach

I know there is a paginate() function but I don't know how or where to use it in my controller.

tried to this

$data = http::get('http://universities.hipolabs.com/search?country=australia')
    ->json()
    ->paginate(10);

Can someone show me how to use paginate?



Solution 1:[1]

The paginate() method is used for database queries. You have got all the data. Maybe you can achieve it in your HTML code. Use JavaScript to control how to display if not much data.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Karl Hill