【发布时间】:2020-02-15 16:11:35
【问题描述】:
我正在使用下拉菜单,它的选项值为 $account->code 但它显示代码和名称
所以我想将代码存储在其列中,并将名称存储在另一列中
这是我的刀片代码:
<div class="form-group col-md-4">
<label>@lang('site.from_account_number')</label>
<select class="form-control select2" style="width: 100%;" name="from_account_number" id="from_account_number">
@foreach ($accounts as $account)
<option value="{{ $account->code }}">
{{ $account->code }} - {{ $account->name }}
</option>
@endforeach
</select>
</div>
这是我的控制器代码:
$depositaction->from_account_number = $request->get('from_account_number');
$record_from_acc_name = Account::find($request->get('from_account_number'));
$depositaction->from_account_name = $record_from_acc_name->name;
但我得到错误说:
ErrorException (E_NOTICE) Trying to get property 'name' of non-object
【问题讨论】:
-
accounts 表的 pk 是什么??
标签: laravel