Не удается удалить morphpivot пользовательские модели фреймворк Laravel
Я использую laravel для проекта, и у меня возникли некоторые проблемы с удалением пользовательских отношений morphPivot.
Когда я пытаюсь удалить отношение, я получаю следующую ошибку:
Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (SQL: delete from `comment` where (`` = 01418755-c68e-4ea5-8043-cef348c47445))'
Из него я понял, что laravel пытается удалить по идентификаторам, но столбец id не имеет имени, поэтому он не может его найти. Тем не менее, я думаю, что четко определил столбец id. Вот реализация моего класса:
<?php
namespace App;
use App\Traits\CanBeBlocked;
use App\Traits\CanBeGhosted;
use App\Traits\CanBeVoted;
use App\Traits\HasUuid;
use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphPivot;
use Illuminate\Support\Facades\DB;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
class Comment extends MorphPivot
{
use HasUuid,
CanBeBlocked,
CanBeGhosted,
CanBeVoted;
protected $casts = [
'id' => 'string'
];
protected $fillable = [
'id',
'parent_id',
'user_id',
'commentable_id',
'commentable_type',
'content',
'created_at',
'updated_at'
];
public $incrementing = false;
public $keyType = 'string';
protected $primaryKey = 'id';
/**
* @brief Users commenting another model
*/
public function commenter()
{
return $this->belongsTo('App\User', 'user_id');
}
/**
* @brief models commented by a User
*/
public function commentable()
{
return $this->morphTo();
}
/**
* @brief replies of the comment
*/
public function replies()
{
return $this->hasMany('App\Comment', 'parent_id');
}
public function parent()
{
return $this->belongsTo('App\Comment');
}
public function repliers()
{
return $this->replies->map(function ($reply, $key) {
return $reply->commenter;
});
}
public function isReply()
{
return $this->parent_id !== null;
}
public function commentOnly($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Builder
{
return Comment::where('parent_id', null);
}
}
и миграции:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comment', function (Blueprint $table) {
$table->uuid('id');
$table->primary('id');
$table->text('content');
$table->boolean('spoiler')->default(false);
$table->boolean('hidden')->default(false);
$table->boolean('edited')->default(false);
$table->uuid('parent_id')->nullable();
$table->uuid('user_id');
$table->uuid('commentable_id');
$table->string('commentable_type');
$table->json('meta')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('comment');
}
}
Заранее благодарю вас за вашу помощь.
Что Laravel V6 двигателем.18.26
У вопроса есть решение - Посмотреть?
Ответы - Не удается удалить morphpivot пользовательские модели фреймворк Laravel / Cannot delete morphpivot Custom model laravel
Помочь в развитии проекта: