I'm trying to export all records from a table, called ingredients, from a custom plugin. I've followed the tutorial here: https://octobercms.com/docs/backend/import-export, but I can't get it to work properly. The problem is that all fields are exported fine, except for the related fields, which stay empty.
My export model class looks as follows:
use [namespace]\[namespace]\Models\Ingredient;
class IngredientsExport extends ExportModel
{
public function exportData($columns, $sessionKey = null)
{
$ingredients = Ingredient::all();
$ingredients->each(function($ingredient) use ($columns) {
$ingredient->addVisible($columns);
});
return $ingredients->toArray();
}
}
In the Ingredient model I've added the relation and $visible property like so:
protected $visible = ['application', 'chemical', 'product'];
public $belongsTo = [
'chemical' => ['[namespace]\[namespace]\Models\Chemical'],
'application' => ['[namespace]\[namespace]\Models\Application'],
'product' => ['[namespace]\[namespace]\Models\Product'],
];
I also tried changing the $visible variable to ['application.name'] but that doesn't work either.
Apparently it should be really easy to achieve, see: https://github.com/octobercms/october/issues/1313. But I really can't get it to work and I can't find any documentation on im/exporting with relations either.
Any ideas? Thanks!