undercode
undercode
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Try to make a repo in github and I'll try when I have time
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
I can't think of anything else, sorry.
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Try php artisan cache:clear
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Exactly! You can specify field types in your $schema variable: https://github.com/calebporzio/sushi?tab=readme-ov-file#custom-schema
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Exactly. And creates a new table if not exsists.
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
This is Sushi function to create the table and its fields:
public function createTable(string $tableName, $firstRow)
{
$this->createTableSafely($tableName, function ($table) use ($firstRow) {
// Add the "id" column if it doesn't already exist in the rows.
if ($this->incrementing && ! array_key_exists($this->primaryKey, $firstRow)) {
$table->increments($this->primaryKey);
}

foreach ($firstRow as $column => $value) {
switch (true) {
case is_int($value):
$type = 'integer';
break;
case is_numeric($value):
$type = 'float';
break;
case is_string($value):
$type = 'string';
break;
case is_object($value) && $value instanceof \DateTime:
$type = 'dateTime';
break;
default:
$type = 'string';
}

if ($column === $this->primaryKey && $type == 'integer') {
$table->increments($this->primaryKey);
continue;
}

$schema = $this->getSchema();

$type = $schema[$column] ?? $type;

$table->{$type}($column)->nullable();
}

if ($this->usesTimestamps() && (! in_array('updated_at', array_keys($firstRow)) || ! in_array('created_at', array_keys($firstRow)))) {
$table->timestamps();
}

$this->afterMigrate($table);
});
}
public function createTable(string $tableName, $firstRow)
{
$this->createTableSafely($tableName, function ($table) use ($firstRow) {
// Add the "id" column if it doesn't already exist in the rows.
if ($this->incrementing && ! array_key_exists($this->primaryKey, $firstRow)) {
$table->increments($this->primaryKey);
}

foreach ($firstRow as $column => $value) {
switch (true) {
case is_int($value):
$type = 'integer';
break;
case is_numeric($value):
$type = 'float';
break;
case is_string($value):
$type = 'string';
break;
case is_object($value) && $value instanceof \DateTime:
$type = 'dateTime';
break;
default:
$type = 'string';
}

if ($column === $this->primaryKey && $type == 'integer') {
$table->increments($this->primaryKey);
continue;
}

$schema = $this->getSchema();

$type = $schema[$column] ?? $type;

$table->{$type}($column)->nullable();
}

if ($this->usesTimestamps() && (! in_array('updated_at', array_keys($firstRow)) || ! in_array('created_at', array_keys($firstRow)))) {
$table->timestamps();
}

$this->afterMigrate($table);
});
}
As you can see, the function creates field types based on the contents of the field.
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Try to remove it
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Do you have a sqlite database in your database folder?
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
No, it's not. It's Sushi's
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Ok, remove $casts and add this line:
protected $schema = [
'IMEI' => 'string',
];
protected $schema = [
'IMEI' => 'string',
];
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
No
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Ok, but you are using Sushi, with uses SQLite to store your data. Try to add this line to your Simcard model:
protected $casts = [ 'IMEI' => 'string'];
protected $casts = [ 'IMEI' => 'string'];
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
ok
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Could you share how you load your json and how you parse it?
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Yes, i did. And with ini_set('precision', 20) the IMEI
89450136240822000001
89450136240822000001
is displayed as
89450136240821993472
89450136240821993472
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Maybe GNU Multiple Precision could help you. https://www.php.net/manual/en/book.gmp.php
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
It seems more a php precision thing than a filament one, because number displayed is different when using ini_set('precision', 20)
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
I see
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
ok
100 replies
FFilament
Created by Shang✨ on 12/26/2024 in #❓┊help
How to solve long string(numeric) issue in datagrid?
Is your field defined like: $table->string('imei') ?
100 replies