getTableReorderColumn() pivot column

I have 3 models one of which is Pivot::class Article, Course, ArticleCourse The pivot uses eloquent-sortable, the Pivot implements Sortable and uses the SortableTrait. Upon attaching thus creating a pivot record the 'sort_when_creating' => true, doesn't seem to fire. Also with:
protected function getTableReorderColumn(): ?string
{
return 'article_course.order_column'; //or 'order_column, both fail;
}
protected function getTableReorderColumn(): ?string
{
return 'article_course.order_column'; //or 'order_column, both fail;
}
When dragging and dropping the records I get:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'article_course.order_column' in 'field list' (Connection: mysql, SQL: update `articles` set `article_course`.`order_column` = 1, `articles`.`updated_at` = 2023-04-03 20:28:40 where `id` = 15)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'article_course.order_column' in 'field list' (Connection: mysql, SQL: update `articles` set `article_course`.`order_column` = 1, `articles`.`updated_at` = 2023-04-03 20:28:40 where `id` = 15)
Any suggestions as how to solve this issue? Are there existing solutions available? Justification: Some articles can be reused within other courses lets say a common recurring one like how to install something. It is to be used within a many to many relationship manager
1 Reply
Sander
SanderOP2y ago
FIXED
// do this:
protected function getTableReorderColumn(): ?string
{
return 'order_column';
}

// but make sure you got this:
//Course
public function articles(): BelongsToMany
{
return $this->belongsToMany(Article::class)
->withPivot('order_column')
->using(ArticleCourse::class);
}
//Article
public function courses(): BelongsToMany
{
return $this->belongsToMany(Course::class)
->withPivot('order_column')
->using(ArticleCourse::class);
}
// do this:
protected function getTableReorderColumn(): ?string
{
return 'order_column';
}

// but make sure you got this:
//Course
public function articles(): BelongsToMany
{
return $this->belongsToMany(Article::class)
->withPivot('order_column')
->using(ArticleCourse::class);
}
//Article
public function courses(): BelongsToMany
{
return $this->belongsToMany(Course::class)
->withPivot('order_column')
->using(ArticleCourse::class);
}
Want results from more Discord servers?
Add your server