I want to use the values of attributes on a model's relationship with Form::label and Form::text. The Form helper was removed from Laravel, so I use 'Form' => 'Collective\Html\FormFacade' instead.
Here is the relationship in the Order Model:
<?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Order extends \Eloquent
{
use SoftDeletes;
public function account_number()
{
return $this->belongsTo('\App\Models\Account_number', 'product_id', 'id');
}
}
And here's the Blade template with Form. The text in the account_number <td> will show:
{"id":4,"user_id":52,"account_type":"alipay","account_no":"xxxxxx","account_name":"xxxxxx","phone":"xxxxxx","created_at":"2017-11-15 14:43:51","updated_at":"2017-11-15 14:43:51","deleted_at":null}
{!! Form::model($order, array('files' => true)) !!}
<table border="1">
<tr>
<td>{!! Form::label('out_trade_no', 'out_trade_no: ') !!}</td>
<td>{!! Form::text('out_trade_no')!!}</td>
</tr>
<tr>
<td>{!! Form::label('account_number', 'account_number: ') !!}</td>
<td>{!! Form::text('account_number')!!}</td>
</tr>
</table>
But I want to show inputs for each account_number attribute separately, not as a JSON string.
I have tried with:
<tr>
<td>{!! Form::label('account_number.id', 'account_number: ') !!}</td>
<td>{!! Form::text('account_number.id')!!}</td>
</tr>
or
<tr>
<td>{!! Form::label('account_number->id', 'account_number: ') !!}</td>
<td>{!! Form::text('account_number->id')!!}</td>
</tr>
or
<tr>
<td>{!! Form::label('account_number', 'account_number: ') !!}</td>
<td>{!! Form::text('account_number["id"]')!!}</td>
</tr>
...but none of these work. They all leave this <td> empty.