Foks
1 month ago

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

Posted 1 month ago by Foks

Hi! I'm currently working on a accounting software, and I'm facing a problem with the Laravel 8 Paginator.

This is the error I'm getting

Method Illuminate\Database\Eloquent\Collection::links does not exist. (View: C:\laragon\www\accounting\resources\views\livewire\accounting-dashboard.blade.php) (View: C:\laragon\www\accounting\resources\views\livewire\accounting-dashboard.blade.php)

This is my accounting-dashboard.blade.php

<div>

    <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">

        @dump(App\Models\Account::find(1)->transactions)

        <div class="flex flex-col">
            <div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
                <div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
                    <div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead>
                            <tr>
                                <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
                                    Name
                                </th>
                                <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
                                    Title
                                </th>
                                <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
                                    Status
                                </th>
                                <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
                                    Role
                                </th>
                                <th class="px-6 py-3 bg-gray-50"></th>
                            </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">

                                @foreach($transactions as $transaction)
                                    <tr>
                                        <td class="px-6 py-4 whitespace-no-wrap">
                                            <div class="flex items-center">
                                                <div class="flex-shrink-0 h-10 w-10">
                                                    <img class="h-10 w-10 rounded-full" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=facearea&amp;facepad=4&amp;w=256&amp;h=256&amp;q=60" alt="">
                                                </div>
                                                <div class="ml-4">
                                                    <div class="text-sm leading-5 font-medium text-gray-900">
                                                        Jane Cooper
                                                    </div>
                                                    <div class="text-sm leading-5 text-gray-500">
                                                        [email protected]
                                                    </div>
                                                </div>
                                            </div>
                                        </td>
                                        <td class="px-6 py-4 whitespace-no-wrap">
                                            <div class="text-sm leading-5 text-gray-900">Regional Paradigm Technician</div>
                                            <div class="text-sm leading-5 text-gray-500">Optimization</div>
                                        </td>
                                        <td class="px-6 py-4 whitespace-no-wrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                              Active
                                            </span>
                                        </td>
                                        <td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
                                            Admin
                                        </td>
                                        <td class="px-6 py-4 whitespace-no-wrap text-right text-sm leading-5 font-medium">
                                            <a href="#" class="text-indigo-600 hover:text-indigo-900">Edit</a>
                                        </td>
                                    </tr>
                                @endforeach

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {{ $transactions->links() }}

</div>

This is my AccountingDashboard.php, which belongs to the .blade file above.

<?php

namespace App\Http\Livewire;

use App\Models\Transaction;
use Livewire\Component;

class AccountingDashboard extends Component
{
    public $transactions = [];

    public function mount()
    {
        $this->transactions = Transaction::all();
    }

    public function render()
    {
        $transaction = Transaction::where('id', '!=', 'aa')->get()->paginate(1);
        return view('livewire.accounting-dashboard', [
            'transactions' => $transaction
        ]);
    }
}

Thanks in advance & Best Regards Foks

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