I have 2 resources: ArticleCategory and Article. They have many to many relationship. Article belongs to System, which is another resource. In article table page (where all the articles are listed), I have a system column that displays system id, it is visible and it works as you can see on the image below.
On single article category page, there is articles field. I can click on 'select' and choose articles I want to attach from article list. Problem is that on that list system id is not visible. I also tried to display system name, but it did not work.
Below I provide you with relevant migrations, models, blueprints.
Schema::create('systems', function (Blueprint $table) {
$table->unsignedInteger('id')->primary();
$table->string('name');
$table->string('image')->nullable();
$table->timestamps();
});
article categories
Schema::create('article_categories', function (Blueprint $table) {
$table->id();
$table->string('title_de')->unique();
$table->string('title_fr')->nullable()->unique();
$table->timestamps();
});
+also create a pivot table for many to many relationship between article categories and articles
Article model
class Article extends Model
{
/** @use HasFactory<ArticleFactory> */
use HasFactory, HasRunwayResource, SoftDeletes;
protected $guarded = [];
/**
* @return BelongsTo<System, Article>
*/
public function system(): BelongsTo
{
return $this->belongsTo(System::class, 'system_id');
}
/**
* @return BelongsToMany<ArticleCategory>
*/
public function articleCategories(): BelongsToMany
{
return $this->belongsToMany(ArticleCategory::class, 'article_article_category', 'article_id', 'article_category_id');
}
...
}
System model
class System extends Model
{
use HasRunwayResource;
protected $guarded = [];
/**
* @return Attribute<string, never>
*/
protected function systemIdentifier(): Attribute
{
return Attribute::make(
get: fn () => $this->id,
set: fn (int $value) => [
'id' => $value,
],
);
}
/**
* @return HasMany<Product>
*/
public function products(): HasMany
{
return $this->hasMany(Product::class);
}
/**
* @return HasMany<Article>
*/
public function articles(): HasMany
{
return $this->hasMany(Article::class);
}
}
Article category model
class ArticleCategory extends Model
{
use HasRunwayResource, LocalisedPropertyAccessorTrait;
protected $guarded = [];
/**
* @return Attribute<string, string>
*/
protected function title(): Attribute
{
return Attribute::make(
get: fn () => $this->getLocalizedProperty('title'),
);
}
/**
* @return BelongsToMany<Article>
*/
public function articles(): BelongsToMany
{
return $this->belongsToMany(Article::class, 'article_article_category', 'article_category_id', 'article_id');
}
/**
* @return BelongsToMany<ProductType>
*/
public function productTypes(): BelongsToMany
{
return $this->belongsToMany(ProductType::class, 'article_category_product_type', 'article_category_id', 'product_type_id');
}
/**
* This method is used for statamic to get the product types for HasMany fieldtype
* as it only supports snake case naming.
*
* @return BelongsToMany<ProductType>
*/
public function product_types(): BelongsToMany
{
return $this->productTypes();
}
}
Description
I have 2 resources: ArticleCategory and Article. They have many to many relationship. Article belongs to System, which is another resource. In article table page (where all the articles are listed), I have a system column that displays system id, it is visible and it works as you can see on the image below.
On single article category page, there is articles field. I can click on 'select' and choose articles I want to attach from article list. Problem is that on that list system id is not visible. I also tried to display system name, but it did not work.
Below I provide you with relevant migrations, models, blueprints.
article migrations
systems migration/schema
article categories
+also create a pivot table for many to many relationship between article categories and articles
Article model
System model
Article category model
Article blueprint
Article category blueprint
System blueprint
Steps to reproduce
Environment
Environment Application Name: Statamic Laravel Version: 11.19.0 PHP Version: 8.3.10 Composer Version: 2.7.8 Environment: local Debug Mode: ENABLED URL: localhost:8080 Maintenance Mode: OFF Timezone: Europe/Zurich Locale: de
Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED
Drivers Broadcasting: null Cache: file Database: sqlite Logs: stack / daily Mail: log Queue: sync Scout: collection Session: file
Locales Installed: de, en, fr LaravelLang\Lang\Plugin: 15.5.6 Locales Version: 2.9.2 Protected: de Publisher Version: 16.4.0
Sentry Enabled: MISSING DSN Environment: local Laravel SDK Version: 4.7.1 PHP SDK Version: 4.8.1 Release: NOT SET Sample Rate Errors: 100% Sample Rate Performance Monitoring: NOT SET Sample Rate Profiling: NOT SET Send Default PII: DISABLED
Statamic Addons: 3 Sites: 1 Stache Watcher: Disabled Static Caching: Disabled Version: 5.19.0 PRO
Statamic Addons statamic-rad-pack/runway: 7.7.3 statamic/eloquent-driver: 4.12.0 tv2regionerne/statamic-safeguard: 1.4.0
Statamic Eloquent Driver Asset Containers: file Assets: eloquent Blueprints: file Collection Trees: eloquent Collections: file Entries: eloquent Forms: file Global Sets: file Global Variables: eloquent Navigation Trees: eloquent Navigations: file Revisions: file Sites: file Taxonomies: file Terms: eloquent Tokens: eloquent