TappNetwork / filament-authentication-log

32 stars 14 forks source link

Route with custom location of user resource edit is not defined #1

Closed iniznet closed 11 months ago

iniznet commented 11 months ago

Hi there,

I got an issue where if you move the default user model into another directory it will result in the Route [filament.admin.resources.users.edit] not defined. error.

After digging into the package, I found that that the issue lies in the file vendor\tapp\filament-authentication-log\src\Resources\AuthenticationLogResource.php, particularly at line 77. The code at this line only extracts the class name without considering the model's location. Consequently, this approach generates an incorrect route. https://github.com/TappNetwork/filament-authentication-log/blob/9a39e39a1b9c7f3b6f11d12e77ec0e3a76d555e2/src/Resources/AuthenticationLogResource.php#L72-L78

In my project, I moved both the user model and the Filament user resource to the Management directory, assigning the namespaces as follows: App\Models\Management and App\Filament\Resources\Management.

Temporary Workaround:

use App\Models\Management\User;

class UserResource extends Resource
{
    protected static ?string $model = User::class;
    protected static ?string $slug = 'users'; // remove 'management' from the slug
...

A possible fix for this issue:

  1. Take anything after Models
  2. Replace the remaining slashes with a dot
  3. Do the original string manipulation
    
    $authenticatable = Str::replace('\\', '.', Str::after($record->authenticatable::class, 'Models\\'));
    $authenticatable = Str::plural(Str::lower($authenticatable));

return new HtmlString(''.class_basename($record->authenticatable::class).'');

mrailton commented 11 months ago

I'm getting the same error, but appears it's from changing the 'id' of the panel away from admin. I am working on a PR to add a new config item for the panel_id that will bypass this issue

andreia commented 11 months ago

@iniznet Thank you for catching and reporting this :) @mrailton Thank you for taking the time to work on this :)