Неверное целочисленное значение: 'caa506cd-a6c6-4907-9a70-81be26324cf3' для столбца 'notifiable_id' - PullRequest
0 голосов
/ 23 сентября 2018

Я следую инструкциям по уведомлениям в Laravel docs, но я получаю сообщение об ошибке

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 
'caa506cd-a6c6-4907-9a70-81be26324cf3' 
for column 'notifiable_id' at row 1 

(SQL: insert into `notifications` (
    `id`, 
    `type`, 
    `data`, 
    `read_at`, 
    `notifiable_id`, 
    `notifiable_type`, 
    `updated_at`, 
    `created_at`
) values (
    18983710-8eaf-4784-8015-63c078e93866, 
    App\Notifications\UserSelectedToInterview, 
    {"company_name":"McDonalds","job_title":null}, 
    , 
    caa506cd-a6c6-4907-9a70-81be26324cf3, 
    App\User, 
    2018-09-23 16:20:24, 2018-09-23 16:20:24)
)

, когда я звоню

// Create the notification for the users
Notification::send(User::whereIn('id', $candidates->pluck('user_id'))
    ->select('id')
    ->get(),

new UserSelectedToInterview($loggedCompany->name, $job->title));

С моей миграцией уведомлений:

Schema::create('notifications', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->string('type');
    $table->morphs('notifiable');
    $table->text('data');
    $table->timestamp('read_at')->nullable();
    $table->timestamps();
});

Я предполагаю, что $table->morphs('notifiable'); ожидает int, но моя модель User использует в качестве первичного ключа uuid.

В моей User модели, которую я указал с protected $keyType = 'string';

Есть идеи, где проблема?

1 Ответ

0 голосов
/ 23 сентября 2018

2 часа спустя стучит головой о стену

В основном проблема, если кому-то интересно, - это метод morph().

Метод, стоящий за этим:

/**
 * Add the proper columns for a polymorphic table.
 *
 * @param  string  $name
 * @param  string|null  $indexName
 * @return void
 */
public function morphs($name, $indexName = null)
{
    $this->unsignedInteger("{$name}_id");

    $this->string("{$name}_type");

    $this->index(["{$name}_id", "{$name}_type"], $indexName);
}

Вместо использования morph() вы можете добавить поля самостоятельно:

$table->string('notifiable_type');
$table->uuid('notifiable_id');
// Don't forget to add the indexes
$table->index(['notifiable_type', 'notifiable_id']);

Прописки к этому ответу Как сделать так, чтобы laravel Blueprints преобразовывал метод добавления столбца после указанного столбца

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...