TappNetwork / filament-authentication-log

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

help with getEloquentQuery

quasiperfect opened this issue · comments

hi

i have overridden you resource class and i want to use getEloquentQuery to filter the results but i didn't had any luck. can you be so kind as to post a example on how to do that ?

Hi @quasiperfect

Sure! :)

To be able to extend and modify the resource, you should override in your project the AuthenticationLogResource and the AuthenticationLogResource's ListAuthenticationLogs.php page.

  • on your AuthenticationLogResource.php, override the getPages() method pointing to your page,
  • on your ListAuthenticationLogs.php page, set the $resource property to your resource.

E.g.:

Your AuthenticationLogResource.php resource extending Tapp\FilamentAuthenticationLog\Resources\AuthenticationLogResource:

<?php

namespace App\Filament\Resources;

//...
use Rappasoft\LaravelAuthenticationLog\Models\AuthenticationLog;
use Tapp\FilamentAuthenticationLog\Resources\AuthenticationLogResource as BaseAuthenticationLogResource;
use App\Filament\Resources\AuthenticationLogResource\Pages;

class AuthenticationLogResource extends BaseAuthenticationLogResource
{
    public static function table(Table $table): Table
    {
        return $table
            ->query(AuthenticationLog::where('ip_address', '127.0.0.1')) // some custom query
            ->columns([
                // ...
            ])
            ->actions([
                // ...
            ])
            ->filters([
                // ...
            ]);
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListAuthenticationLogs::route('/'), // your page here (see namespace above: use App\Filament\Resources\AuthenticationLogResource\Pages;)
        ];
    }
}

Your ListAuthenticationLogs.php page:

<?php

namespace App\Filament\Resources\AuthenticationLogResource\Pages;

use Filament\Resources\Pages\ListRecords;
use App\Filament\Resources\AuthenticationLogResource;

class ListAuthenticationLogs extends ListRecords
{
    protected static string $resource = AuthenticationLogResource::class; // you resource here (see namespace above: use App\Filament\Resources\AuthenticationLogResource;)
}

Please let me know if it's working for you :)

thanks @andreia it works great :)