Get checkbox options from database in laravel

The view:

[code]

<div class=”form-group”>
@foreach($publicationPurposes as $publicationPurpose)
<div class=”checkbox”>
<label>
<input name=”purpose[]” id=”purpose{{ $publicationPurpose->id }}” type=”checkbox” value=”{{ $publicationPurpose->id }}” >
{{ $publicationPurpose->name }}
</label>
</div>
@endforeach
</div>

[/code]

The database:

checkbox from database laravel

the Controller:

[code]

$publicationPurposes = PublicationPurpose::with([‘publicationPurposeMediaType’ => function($query){
$query->with([‘publicationPurposeTags’, ‘mediaType’]);
}])->get();
debug($publicationPurposes);

return view(‘the-view’)->with([‘publicationPurposes’ => $publicationPurposes,]);

[/code]

 

CategoriesUncategorized

Leave a Reply

Your email address will not be published.