I'm certainly not a laravel expert, but here's how I'm doing something similar. (adjusted to use your info)
In my controller
public function edit($id)
{
$profile = Profile::find($id);
//get all itens
$iten = Iten::get();
//just get the itens associated with profile from the pivot table, returned as an array
$associated_itens = DB::table('profile_iten')->where('profile_id','=',$id)->lists('iten_id');
return View::make('profile.edit', compact('profile','itens','associated_itens'));
}
Then on my edit form I did this for the checkboxes
{{ Form::label('itens', 'Associated Itens') }}
@foreach($itens as $key => $val)
<?php
$checked = false;
//as we loop through a list of all itens, we compare to the values retrieved from our pivot table
if(in_array($val->id, $associated_itens)) $checked = true;
?>
{{ Form::checkbox('itens[]', $val->id, $checked) }}
{{ $val->name}}
@endforeach
Hope this helps.
Hi, i tried what gregbeatrice posted, but in laravel 5 where it seems no matter what i do my code is overidden and i still get all my checkboxes checked in the edit page. Any other idea? i checked the $checked value and it's correct on all the cases but it seems to be ignored...
i made it work by using another field name in the update form, and on update i did something like:
$item->field = $request->new_field_name;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community