t0berius
1 month ago

laravel load() with paginate()

Posted 1 month ago by t0berius

Using the following query:

    $product->load(['stockItems' => function ($query) {
        $query->available()->oldest()->paginate(2);
    }]);

The results are fetched correctly (dd($product); shows the correct "batch" of related attributes), but when using:

{{ $product->stockItems->links() }}

inside blade it seems like the paginate() methos not called correctly, some expected methods are not available:

Method Illuminate\Database\Eloquent\Collection::links does not exist. (View:

Any idea how to get this solved?

Please sign in or create an account to participate in this conversation.