Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SimonQ's avatar

Fill Existing Form with Array from Model

I have simple form where users submit their info into a database.

I pull that information to an admin side where the admin can see what the users have filled out by populating that form with the users input.

I am able to grab single elements (i.e. text inputs and text fields) via $client->name but, am not sure how to populate the form with an array (checkboxes, and radio fields). When I try to do the same for array items it checks off whatever I have listed last.

How would I populate a checkbox and radio fields via the array inputs through the model?

0 likes
2 replies
SimonQ's avatar

In my model I am grabbing the data

    public function show($id)
    {
        return view('admin.show', ['client' => Client::findOrFail($id)]);
    }

In the view, I am populating the value field here

{!! Form::text('name', $client->name, ['class' => 'form-control', 'required' => 'required', 'placeholder' => 'Name']) !!}

This works for single elements but not sure how to proceed with array elements like a radio:

<div class="radio @if($errors->first('rest')) has-error @endif">
    <label for="rest">
        {!! Form::radio('rest[]',1,  $client->rest, ['id' => 'rest1']) !!} Yes
    </label>
</div>
<div class="radio @if($errors->first('rest')) has-error @endif">
    <label for="rest">
        {!! Form::radio('rest[]',0,  $client->rest, ['id' => 'rest0']) !!} No
    </label>
</div>

That just ends up populating the last filled field (i.e. No).

Would the solution to this also be the same to checkboxes as well?

Please or to participate in this conversation.