2017-02-24 20:54
浏览 51


I have a Voice Model where I save all the new voices and each voice has name and language field. My Second Model is Device Model, I want to populate these voices on the Device form view as Checkboxes and let the user to pick one or more than one and save it to related Device as JSON.

Someone - help! :)

How I want to save the voices to the Robot


Voice Model

public $fillable = [

public function devices()
  return $this->belongsToMany('App\Models\Device');

Device Model

public $fillable = [

public function voices()
  return $this->hasMany('App\Models\Voice');

Robot Form

<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']) !!}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongziche8030 2017-02-24 21:29

    I use this 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')
            @if ($attr_key == 'readonly')
                @if($attr_value == 'readonly')
                    readonly="readonly" disabled="disabled"
        @if ($val=="1")
        @if (isset($attr['id']))
            name="{{ $attr['id'] }}"
        @endif value="1">
    @if (isset($attr['id']))
        <label for="{{ $attr['id'] }}" >
            {{ $label }}

    Where there are 2 checkboxes as a kind of hack to always send the checkbox value, even if it's unchecked, based on this answer.

    点赞 评论

相关推荐 更多相似问题