Hi again!
I have a problem using relations and I cannot solve by reading documentation or demo-code either:
I want show a field from the related table that is not an ID-field.
So here is the created resource:
<?php
namespace App\KV\Dashboard\Resource;
use App\KV\Dashboard\DataSources\Data;
use App\KV\Dashboard\Glasses\HmFgKtfgDefAllQ;
use App\KV\Dashboard\Inputs\HmFgKtfgCopyUpButton;
use koolreport\dashboard\containers\Html;
use koolreport\dashboard\containers\Modal;
use koolreport\dashboard\containers\Panel;
use koolreport\dashboard\containers\Row;
use koolreport\dashboard\fields\RelationLink;
use koolreport\dashboard\inputs\Button;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\admin\relations\BelongsTo;
class HmFgKtfgDef extends \koolreport\dashboard\admin\Resource
{
protected function onCreated()
{
$this
->manageTable("def_fg_quartal")
->inSource(Data::class)
->listScreen()
->adminTable()
->pageSize(20)
;
}
protected function relations()
{
return [
BelongsTo::resource(AvdDefFg::class)->link(['fg' => 'fg'])->title('fg-Name'),
];
}
protected function fields()
{
return [
ID::create('kv_quartal')->label('KV-Quartal')->showOnUpdate(true),
ID::create('ktfg')->label('Kostenträger-FG')->showOnUpdate(true),
ID::create('fg')->label('Fachgruppen-ID')->showOnUpdate(true),
RelationLink::create('fg')->label('Fachgruppen-Name')
->formatUsing(function($value,$row){ return $row['fg']; })
->linkTo(AvdDefFg::class)
];
}
protected function highlights()
{
return [
Panel::create()->header('<h4>Tools</h4>')->type('primary')->sub([
Row::create()->sub([
Html::h5('Quartalskonfiguration übertragen.'),
Html::p('Die FG/KTFG-Konfiguration wird damit automatisiert z.B. von 20204 nach 20211 übertragen.
Veränderte Werte können dann dort editiert werden. Die benötigten Werte ermittelt das System selbst.'),
Button::create()->text('Quartalskonfiguration übertragen')->onClick(function(){ return Modal::show('QEingabe');})
]),
Modal::create('QEingabe')->sub([
Html::h5('Bist du sicher, dass du diese Operation jetzt ausführen möchtest?'),
Html::hr(),
HmFgKtfgCopyUpButton::create()->onClick(function(){
return Modal::hide("QEingabe");
}),
])->title('Quartale auswählen')->showCloseIcon(true)->size("md")->open(false)->animation('fade')
])
];
}
protected function glasses()
{
return [
HmFgKtfgDefAllQ::create()
];
}
}
And here is the related resource:
<?php
namespace App\KV\Dashboard\Resource;
use App\KV\Dashboard\DataSources\Data;
use koolreport\dashboard\admin\relations\HasMany;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\fields\Text;
class AvdDefFg extends \koolreport\dashboard\admin\Resource
{
protected function onCreated()
{
$this
->manageTable("def_fg")
->inSource(Data::class)
->listScreen()
->adminTable()
->pageSize(20)
;
}
protected function relations(){
return [
HasMany::resource(HmFgKtfgDef::class)->link(['fg' => 'fg'])->title('Fachgruppen-Name')
];
}
protected function fields(){
return [
ID::create('fg')->label('FG-ID'),
ID::create('text')->label('Fachgruppen-Name lang'),
Text::create('web_text')->label('Fachgruppen-Name Web'),
Text::create('abk')->label('Fachgruppe-Abkürzung')
];
}
}
The thing I want to do is to display the field 'text' related to the field 'fg'.
I think I made something wrong with the relation or you use relations an other way as I think from the databse way...
Can you help me?
Regards, Peter