mardi 7 février 2017

form model binding values to select dropdown in Laravel

I have a pivot table with additional attributes. I would like to bind those in two different select field. Let me explain:

Users

id

name

...

Language_User

id

user_id

language_id

type('learn','native')

Language

id

language('English','French','Spanish','German',...)

I have a form with two select fields. One for What language user wants to learn and another to tell which language they can teach(which is there native one)

my query

$native = Language::pluck('language','id');
$learn  = Language::pluck('language','id');
$settings = User::with('languages')->where('id',Auth::user()->id)->get();
return view('/users/settings',compact('settings','native','learn'));       

my form below

@foreach ($settings as $setting)

{!! Form::model($setting,[ 'method' =>'PATCH', 'url' => ['/users/settings/'.$setting->id.'/update']]) !!}


  <div class="form-group">
    {!! Form::label('learn', 'Learn:') !!}
    {!! Form::select('learn', $learn, null, ['class'=>'form-control']) !!}  
  </div>

  <div class="form-group">
    {!! Form::label('native', 'Native:') !!}
    {!! Form::select('native', $native, null, ['class'=>'form-control']) !!}  
  </div>

    <div class="form-group">
    {!! Form::label('search_status', 'Status:') !!}
    {!! Form::select('search_status', ['engaged' => 'Engaged', 'available' => 'Available'], null, ['class'=>'form-control']) !!} 
  </div>

  <div class="form-group">
    {!! Form::submit('UPDATE SETTINGS', ['class'=>' btn btn-primary btn-block']) !!}
  </div>

@endforeach

{!! Form::close() !!}

The problem is both the select field(learn and native) needs to be binded to same column 'type' which is in pivot table 'language_user' but for each user it has two types one is learn language_id and another is teach language_id for user. I have attached $settings which does bind select field 'search_status'. But because user table has no field for learn or native it wont bind, I can though use ::with('languages') to bind but I dont know how to bind for this scenario.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2llb4aa
via IFTTT

Aucun commentaire:

Enregistrer un commentaire