0
我需要制作一个自定义字段,就像清单一样,但是在一个表格中并且带有第二个字段“order”。
这是我有:如何使用数据透视表中的额外列
- 模型1:用关系“belongsToMany”条件
- 模型2:子服务
这两款机型在与具有两个表products_service关系foreign_keys加上“订单”列
我不明白的是:
如何保存额外的信息与背包。
我知道,我可以用这样的:
$user->roles()->updateExistingPivot($roleId, $attributes);
,但我应该在哪里放呢?
这里是我的代码:
class Condition extends Model
{
use CrudTrait;
use Searchable;
public function relService()
{
//dd($this->belongsToMany(SubService::class, 'conditions_service')->withPivot('weight')->withTimestamps());
return $this->belongsToMany(SubService::class, 'conditions_service')->withPivot('weight')->withTimestamps();
}
}
class SubService extends Model
{
use Searchable;
use CrudTrait;
public function conditions()
{
return $this->belongsToMany(Condition::class, 'conditions_service')->withPivot('weight')->withTimestamps();
}
}
这里是我的自定义字段类型:
<!-- select2 -->
<div @include('crud::inc.field_wrapper_attributes') >
<label>{!! $field['label'] !!}</label>
@include('crud::inc.field_translatable_icon')
<?php $entity_model = $crud->getModel(); ?>
<div class="row">
<div class="col-sm-12">
<table id="crudTable" class="table table-bordered table-striped display">
<thead>
<tr>
@if ($crud->details_row)
<th></th> <!-- expand/minimize button column -->
@endif
{{-- Table columns --}}
<th>Seleziona</th>
<th>Ordine</th>
{{--<th>Ordine <i class="fa fa-arrow-up" aria-hidden="true"></i></th>
<th>Ordine <i class="fa fa-arrow-down" aria-hidden="true"></i></th>--}}
{{--$tst = $connected_entity_entry->relService->whereIn('id', $connected_entity_entry->id)--}}
</tr>
</thead>
<tbody>
@foreach ($field['model']::all() as $connected_entity_entry) {{--var_dump((empty($connected_entity_entry->conditions->toArray())?"puppa":(empty($connected_entity_entry->conditions->whereIn('id', $connected_entity_entry->id)->toArray())?"puppa uguale":$connected_entity_entry->conditions->whereIn('id', $connected_entity_entry->id)))) --}}
{{-- dump($connected_entity_entry->getPriority($connected_entity_entry->id)) --}}
<tr>
<th scope="row">
<div class="col-sm-4">
<div class="checkbox">
<label>
<input type="checkbox"
name="{{ $field['name'] }}[]"
value="{{ $connected_entity_entry->id }}"
@if((old($field["name"]) && in_array($connected_entity_entry->id, old($field["name"]))) || (isset($field['value']) && in_array($connected_entity_entry->id, $field['value']->pluck('id', 'id')->toArray())))
checked="checked"
@endif > {!! $connected_entity_entry->{$field['attribute']} !!}
</label>
</div>
</div>
</th>
<td>{{[email protected]('crud::fields.number')--}}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
{{-- HINT --}}
@if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
@endif
</div>
</div>
谢谢您的帮助! 戴夫
我改进了q的格式在第二课结束时添加一个'}'字符来完成代码示例。 – zx485