1

This is part of my code:

$form = new Form(new Shop());
$form->tab('terminal', function (Form $form) use ($id) {
        $form->hasMany('shopterminal', '', function (Form\NestedForm $form) {
            $form->text('terminal_num', 'terminal number')->required();
            $form->select('poz_type', 'POS type')->options(['static' => 'one', 'dynamic' => 'two'])->required();
            $form->select('psp_id', 'POZ name')->options(Psp::pluck('name', 'id'))->required();
            $form->text('sheba', 'sheba number');
            $form->text('account_num', 'account number')->required();
            $form->select('bank_id', 'bank name')->options(Bank::pluck('name', 'id'))->required();

    dd($form);

});

Here is the result of dd($form):

enter image description here

I need to get the value of terminal_image item (which is 15841949062134.png). Any idea how can I get it?

Noted that, neither of below syntax works:

  • $form->get('terminal_image')
  • $form->select('terminal_image')
  • $form->terminal_image
  • $form()->terminal_image
  • $form->relation->terminal_image
Martin AJ
  • 6,261
  • 8
  • 53
  • 111
  • Did you try to use relation name to get your data, something like this: `$form->shopterminal->terminal_image` ? – zlatan Mar 17 '20 at 08:38
  • Just twll me one thing where are you trying to catch the termianal image before returning the form or after returning? – Shohanur Apr 06 '20 at 10:17

2 Answers2

0

For your specific example:

$form->form->model->shopterminal[0]->terminal_image
GTCrais
  • 2,039
  • 2
  • 26
  • 32
  • Edited my answer. Additionally, I wanted to mention, I think your relationship structure is really weird. – GTCrais Mar 17 '20 at 08:48
  • Thanks for editing, but `$form->form` throws `undefined property`. – Martin AJ Mar 17 '20 at 08:50
  • That's weird, the dump you posted shows that `form` property is a `Form` class. Are you maybe iterating over `$forms` then calling `$form->form` for each of those forms? Either way, it would be easier if you updated your question with code for `NestedForm` class, `Form` class, `Shop` class and `TerminalAccount` class. – GTCrais Mar 17 '20 at 08:54
0

you can use :

$form->form->model->relations['shopterminal']->items[0]->attributes['terminal_image']