Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method Illuminate\Database\Eloquent\Collection::total does not exist. #510

Closed
Piket564 opened this issue Oct 17, 2021 · 1 comment
Closed

Comments

@Piket564
Copy link

I'm recreating a Datatable to show the users, clicking on the Select All checkbox, it throw an exception on Collection::total does not exist.
image

UserTable.php

<?php

namespace App\Http\Livewire;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

class UserTable extends DataTableComponent
{

    public bool $viewingManage = false;
    public $currentUser;
    public bool $paginationEnabled = false;
    public bool $columnSelect = false;
    public array $bulkActions = [
        'exportSelected' => 'Esporta',
    ];

    public function columns(): array
    {
        return [
            Column::make(__('Name'))
                ->sortable()
                ->searchable(),
            Column::make(__('E-mail'), 'email')
                ->sortable()
                ->searchable(),
            Column::make(__('Roles'), 'null'),
            Column::make(__('Permissions'), 'null'),
            Column::make(__('Verified'), 'email_verified_at')
                ->sortable(),
            Column::make(__('Manage'), null),
        ];
    }

    public function query(): Builder
    {
        return User::query();
    }

    public function rowView(): string
    {
        return 'users.row';
    }

    public function exportSelected()
    {
        $this->alert('error', 'Funzione in aggiornamento.', [
            'position' => 'center',
            'timer' => null,
            'toast' => true,
            'text' => '',
            'confirmButtonText' => 'OK',
            'cancelButtonText' => 'Cancella',
            'showCancelButton' => false,
            'showConfirmButton' => true,
        ]);
    }

    public function manage($id)
    {
        $this->viewingManage = true;
        $this->currentUser = User::findOrFail($id);
    }

    public function modalsView(): string
    {
        return 'users.manage';
    }

    public function getTableRowUrl(): string
    {
        return '#';
    }

    public function saveUsers()
    {
        session()->flash('message', 'Post successfully updated.');
        $this->resetModal();
    }

    public function resetModal(): void
    {
        $this->reset('viewingManage', 'currentUser');
    }

    public function loginUsers()
    {
        $userRoles = Auth::user()->getRoleNames()->toArray();

        if (in_array('Amministratore', $userRoles)) {
            Auth::loginUsingId($this->currentUser->id, true);
        } else {
            $this->alert('error', 'Impossibile accedere, non si dispone delle autorizzazioni necessarie!', [
                'position' => 'center',
                'timer' => null,
                'toast' => true,
                'text' => '',
                'confirmButtonText' => 'OK',
                'cancelButtonText' => 'Cancella',
                'showCancelButton' => false,
                'showConfirmButton' => true,
            ]);
        }
        $this->resetModal();
        return redirect(route('dashboard'));
    }
}
@rappasoft
Copy link
Owner

Fixed next release: 3eeb4f6

@rappasoft rappasoft mentioned this issue Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants