LaraBABA's avatar

Pagination in laravel 5.5 cannot get it to show up

Hello,

In my controller I have this: use Illuminate\Pagination\Paginator;

public function index()
{
$companies = DB::table('companies')->get();
$paginators = DB::table('companies')->simplePaginate(5);
return view('company.index', ['companies' => $companies, 'paginators' => $paginators]);
}

In the view

            <div class="container">
            <nav aria-label="Page navigation">
            <ul class="pagination">
            @foreach ($paginators as $paginator)
            {{ $paginator->$paginators }}
            @endforeach
            </ul>
            </nav>
            </div>

            {{ $paginators->links() }}

I am getting this error:

ErrorException (E_ERROR) Undefined property: stdClass::$

(View: C:\laragon\www\website\resources\views\company\index.blade.php)

                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
                </nav>
                </div>
    
                <?php echo e($paginators->links()); ?>
    

    Any idea why please? First time I try the pagination in Laravel:-)

    Thank you.

0 likes
1 reply
ftrillo's avatar
@foreach ($paginators as $paginator)
    {{ $paginator->$paginators }} // the $ after -> is a mistake
@endforeach

Also the loop should probably look like this:

@foreach ($paginators as $company)
    {{ $company->name}} // or whatever attribute of the companies you want to display
@endforeach
1 like

Please or to participate in this conversation.