TappNetwork / filament-authentication-log

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Route with custom location of user resource edit is not defined

iniznet opened this issue · comments

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.

->formatStateUsing(function (?string $state, Model $record) {
if (! $record->authenticatable_id) {
return new HtmlString('—');
}
return new HtmlString('<a href="'.route('filament.admin.resources.'.Str::plural((Str::lower(class_basename($record->authenticatable::class)))).'.edit', ['record' => $record->authenticatable_id]).'" class="inline-flex items-center justify-center hover:underline focus:outline-none focus:underline filament-tables-link text-primary-600 hover:text-primary-500 text-sm font-medium filament-tables-link-action">'.class_basename($record->authenticatable::class).'</a>');
})

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
$https://github.com/TappNetwork/filament-authentication-log/issues/%3C/span%3E" target="_blank" rel="nofollowauthenticatable = Str::replace('\\', '.', Str::after($record->authenticatable::class, 'Models\\'));
$authenticatable = Str::plural(Str::lower($authenticatable));

return new HtmlString('<a href="'.route('filament.admin.resources.'.$authenticatable.'.edit', ['record' => $record->authenticatable_id]).'" class="inline-flex items-center justify-center text-sm font-medium hover:underline focus:outline-none focus:underline filament-tables-link text-primary-600 hover:text-primary-500 filament-tables-link-action">'.class_basename($record->authenticatable::class).'</a>');

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

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