I want to use attribute values ββto model relationship with Form::label and Form::text . The Form Helper has been removed from Laravel, so I use 'Form' => 'Collective\Html\FormFacade' .
Here is the relation 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 is the Blade template with Form . The text in 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 the inputs for each account_number attribute separately, and not as a JSON string.
I 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 not one of these works. They all leave this <td> empty.
php forms laravel laravel-5 laravel-eloquent
Kris roofe
source share