Support the ongoing development of →
Database Eloquent Forms
Last updated 10 months ago.

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)
		$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}}

Hope this helps.

Last updated 10 months ago.

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;

Last updated 7 years ago.

Sign in to participate in this thread!


Your banner here too?

sytker sytker Joined 29 Apr 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.