F
Filamentβ€’10mo ago
ericmp

How to use filament table when record key is not an integer?

I published the sessions table. I created a filament resource for the sessions table. The issue comes when i try to delete multiple rows via it's table. It just deletes them all. I guess this is because the sessions table doesn't have a "regular id" field, but instead has a id varchar column type. ($table->string('id')->primary();) So seems filament expect the id to be an integer, and somehow cant handle it and selects all the records in the table. Im not sure if the table record key can be changed or what should i do to make it work in all my other resources, bulk actions just work fine, is just with this table, which has the id primary key not integer
7 Replies
Abel Cobreros
Abel Cobrerosβ€’10mo ago
How did you configure the model? You would probably need to override these parameters in there
Abel Cobreros
Abel Cobrerosβ€’10mo ago
No description
Abel Cobreros
Abel Cobrerosβ€’10mo ago
Set $incrementing to false and $keyType to 'string' and see if that works Is there a reason you have to set the key as a string type? Can't you have the id set to bigInteger like the rest and add a unique "reference" or "code" column?
ericmp
ericmpOPβ€’10mo ago
so far i have it like this:
class Session extends Model
{
use HasFactory;

protected $casts = [
'last_activity' => 'datetime:U',
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
class Session extends Model
{
use HasFactory;

protected $casts = [
'last_activity' => 'datetime:U',
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
ill try to configure it as u say, lets see idk, i just use the default laravel session table structure seems protected $keyType = 'string'; does the trick! it works. thanks πŸ™
Abel Cobreros
Abel Cobrerosβ€’10mo ago
awesome! glad to help
ericmp
ericmpOPβ€’10mo ago
ud change the table session structure? i mean, i wont just in case. idk how laravel handles that table behind the scenes
Abel Cobreros
Abel Cobrerosβ€’10mo ago
To be honest I never used sessions with database, but yeah I would keep it as it comes by default
Want results from more Discord servers?
Add your server