You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is another approach to make Laravel Nova work with models that have a UUID as their primary key. This approach requires two changes:
Add the method Schema::morphUsingUuids() to the boot method of NovaServiceProvider. This will force the migration to create an action table with string types instead of int types
Create a trait or abstract class for your custom models that set the primary key type to string and sets a UUID value when the primary key is empty when creating a new model.
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Ramsey\Uuid\Uuid;
abstract class UuidModel extends Model
{
protected static function boot(): void
{
parent::boot();
static::creating(static function ($model) {
if (empty($model->{$model->getKeyName()})) {
$model->{$model->getKeyName()} = Uuid::uuid4()->toString();
}
});
}
public function getIncrementing(): bool
{
return false;
}
public function getKeyType(): string
{
return 'string';
}
}
Also if I type a single character such as f it will error something to do with an aggregate search.
If I edit the Search/PrimaryKey 's invoke method to put a cast it works.
But how to apply such a modification to Nova?
The text was updated successfully, but these errors were encountered: