我有一个语音模型,我保存所有新的声音,每个声音都有名称和语言字段。我的第二个模型是设备模型( Device ),我希望将这些声音作为复选框填充到设备窗体视图中,让用户选择一个或多个声音并将其保存到相关设备上作为JSON。
救命啊!)
我想把声音保存给机器人
{
"voice_name":"sample1",
"voice_language":"English"
}语音模型
public $fillable = [
'name',
'language'
];
public function devices()
{
return $this->belongsToMany('App\Models\Device');
}设备模型
public $fillable = [
'device_name',
'version',
'voices'
];
public function voices()
{
return $this->hasMany('App\Models\Voice');
}机器人形式
<div class="form-group">
{!! Form::label('device_name', 'Device Name:') !!}
{!! Form::text('device_name', null, ['class' => 'form-control') !!}
{!! Form::label('version', 'version:') !!}
{!! Form::text('version', null, ['class' => 'form-control') !!}
<div class="form-group">
{!! Form::label('voices', 'Voices:') !!}
//I want to list all the voices here as Checkboxes
{!! Form::checkbox('voices[]', null, ['class' => 'form-control']) !!}
</div>发布于 2017-02-24 21:29:04
我使用这个selectinput.blade.php
<input type="hidden" name="{{$attr['id']}}" value="0" />
<input type="checkbox" class="filled-in"
@foreach ($attr as $attr_key => $attr_value)
@if ($attr_key == 'disabled')
@if($attr_value == 'disabled')
disabled="disabled"
@endif
@else
@if ($attr_key == 'readonly')
@if($attr_value == 'readonly')
readonly="readonly" disabled="disabled"
@endif
@else
{{$attr_key}}="{{$attr_value}}"
@endif
@endif
@endforeach
@if ($val=="1")
checked
@endif
@if (isset($attr['id']))
name="{{ $attr['id'] }}"
@endif value="1">
@if (isset($attr['id']))
<label for="{{ $attr['id'] }}" >
{{ $label }}
</label>
@endif在有两个复选框作为一种黑客总是发送复选框值,即使它是未选中的,based on this answer。
https://stackoverflow.com/questions/42448104
复制相似问题