1

The interface that showed is using @foreach method to display . Hence , i want to know how to pass only one checkbox (view) into controller.

Below is the view coding.

@foreach($articles as $article)
<tr>
<td>{{ $article->jenis_simptom}}</td>
<td style="width: 10px">
<input type="checkbox" value="{{ $article->jenis_simptom}}" name="{{ $article->id }">
</td>
</tr>
@endforeach

Thank You

Here is the dummy interface

2 Answers 2

1

Use articles[] as html field name with $article->id as a key

@foreach($articles as $article)
    <tr>
        <td>{{ $article->jenis_simptom}}</td>
        <td style="width: 10px">
            <input type="checkbox" value="{{ $article->jenis_simptom}}" name="articles[{{ $article->id }]">
        </td>
    </tr>
@endforeach

In your controller you'll be able to loop thru submitted array which will contain only elements that were checked in your html

foreach ($request->input('articles') as $key => $value) {
    // $key will contain your article id
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Laravel Collective forms. If you're using Laravel 4, it works out of the box, for Laravel 5 you should install the package.

{!! Form::open(array('action' => 'Controller@store')) !!}
    {!! Form::checkbox('name', 'value') !!}
    {!! Form::submit('Send') !!}
{!! Form::close() !!}

When user submits the form, store action of Controller catches all form data, including checked checkboxes and puts it in $request variable.

public function store(Request $request)
{
    dd($request);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.