View on GitLab

Checks and Radios

x-larastrap::check is used for a single checkbox, but many other variants are available.

<x-larastrap::check label="A Classic Checkbox" />
<div class="row mb-3">
  <label for="check-960ed0691aafac6893918abf4e65d347" class="col-4 col-form-label">A Classic Checkbox</label>
  <div class="col-8">
    <div class="form-check mt-1">
      <input id="check-960ed0691aafac6893918abf4e65d347" type="checkbox" class="form-check-input" name="k4hu2NZaL2">
    </div>
  </div>
</div>

switch

Adding the switch parameter to a single x-larastrap::check element, it will be presented as a Bootstrap switch.

<x-larastrap::check switch label="A Switch" />
<div class="row mb-3">
  <label for="check-013e7ccb1d9e0c7e74a009e6e183af0b" class="col-4 col-form-label">A Switch</label>
  <div class="col-8">
    <div class="form-check form-switch mt-1">
      <input id="check-013e7ccb1d9e0c7e74a009e6e183af0b" type="checkbox" class="form-check-input" name="F0ClusO1um">
    </div>
  </div>
</div>

inline

The inline parameter is useful to alter the layout of the checkbox component.

By default x-larastrap::check is handled as any other Input element (the position of label and input are determined by the parent Form formview ), while inline groups the label with the actual checkbox for a more classic visualization.

Horizontal form, non-inline checkbox

Vertical form, non-inline checkbox

Horizontal form, inline checkbox

Vertical form, inline checkbox
<x-larastrap::form formview="horizontal">
    <div class="alert alert-info">Horizontal form, non-inline checkbox</div>
    <x-larastrap::text label="Reference Text" />
    <x-larastrap::check label="Non-Inline Check" />
</x-larastrap::form>

<hr>

<x-larastrap::form formview="vertical">
    <div class="alert alert-info">Vertical form, non-inline checkbox</div>
    <x-larastrap::text label="Reference Text" />
    <x-larastrap::check label="Non-Inline Check" />
</x-larastrap::form>

<hr>

<x-larastrap::form formview="horizontal">
    <div class="alert alert-info">Horizontal form, inline checkbox</div>
    <x-larastrap::text label="Reference Text" />
    <x-larastrap::check label="Inline Check" inline />
</x-larastrap::form>

<hr>

<x-larastrap::form formview="vertical">
    <div class="alert alert-info">Vertical form, inline checkbox</div>
    <x-larastrap::text label="Reference Text" />
    <x-larastrap::check label="Inline Check" inline />
</x-larastrap::form>
<form id="form-6f4922f45568161a8cdf4ad2299f6d23" class="" method="post" name="form-6f4922f45568161a8cdf4ad2299f6d23">
  <input type="hidden" name="_token" value="7aLiLLQwGLgzP5ztw23nAA0AQrhsjayfhrlvlZ7J" autocomplete="off">
  <div class="alert alert-info">
    Horizontal form, non-inline checkbox
  </div>
  <div class="row mb-3">
    <label for="input-2e1cc4accbf13adb0a8ad3ce1912c9f8" class="col-4 col-form-label">Reference Text</label>
    <div class="col-8">
      <input id="input-2e1cc4accbf13adb0a8ad3ce1912c9f8" type="text" class="form-control" name="CWJ9IShftb" value="">
    </div>
  </div>
  <div class="row mb-3">
    <label for="check-5bb4929c0073a4d01950df437f7808c8" class="col-4 col-form-label">Non-Inline Check</label>
    <div class="col-8">
      <div class="form-check mt-1">
        <input id="check-5bb4929c0073a4d01950df437f7808c8" type="checkbox" class="form-check-input" name="EEmQU68GRW">
      </div>
    </div>
  </div>
  <div class="col-12 text-end">
    <button id="button-222102cb808243971bd4c33dd2a51752" class="btn btn-primary" type="submit">Save</button>
  </div>
</form>
<hr>
<form id="form-4e732ced3463d06de0ca9a15b6153677" class="" method="post" name="form-4e732ced3463d06de0ca9a15b6153677">
  <input type="hidden" name="_token" value="7aLiLLQwGLgzP5ztw23nAA0AQrhsjayfhrlvlZ7J" autocomplete="off">
  <div class="alert alert-info">
    Vertical form, non-inline checkbox
  </div>
  <div class="mb-3">
    <label for="input-0c6928d0eaf67643a72b069047ac0816" class="form-label">Reference Text</label> <input id="input-0c6928d0eaf67643a72b069047ac0816" type="text" class="form-control" name="taZIkt74g4" value="">
  </div>
  <div class="mb-3">
    <label for="check-5efc64ff3ce1d38851a9817e76214591" class="form-label">Non-Inline Check</label>
    <div class="form-check mt-1">
      <input id="check-5efc64ff3ce1d38851a9817e76214591" type="checkbox" class="form-check-input" name="9LEUE53Y8G">
    </div>
  </div>
  <div class="col-12 text-end">
    <button id="button-ad6f1229433e02e545b9b598df61ed42" class="btn btn-primary" type="submit">Save</button>
  </div>
</form>
<hr>
<form id="form-e369853df766fa44e1ed0ff613f563bd" class="" method="post" name="form-e369853df766fa44e1ed0ff613f563bd">
  <input type="hidden" name="_token" value="7aLiLLQwGLgzP5ztw23nAA0AQrhsjayfhrlvlZ7J" autocomplete="off">
  <div class="alert alert-info">
    Horizontal form, inline checkbox
  </div>
  <div class="row mb-3">
    <label for="input-42979af871a76af5832513e92eec0da7" class="col-4 col-form-label">Reference Text</label>
    <div class="col-8">
      <input id="input-42979af871a76af5832513e92eec0da7" type="text" class="form-control" name="tz9Dt0AbZz" value="">
    </div>
  </div>
  <div class="row mb-3">
    <div class="col-8">
      <div class="form-check mt-1">
        <input id="check-8228aae519895cec37c7111d37733cb9" type="checkbox" class="form-check-input" name="7EyjNi1hAt"> <label for="check-8228aae519895cec37c7111d37733cb9" class="">Inline Check</label>
      </div>
    </div>
  </div>
  <div class="col-12 text-end">
    <button id="button-802f32930e5aff0e56f8bb90be191387" class="btn btn-primary" type="submit">Save</button>
  </div>
</form>
<hr>
<form id="form-17e62166fc8586dfa4d1bc0e1742c08b" class="" method="post" name="form-17e62166fc8586dfa4d1bc0e1742c08b">
  <input type="hidden" name="_token" value="7aLiLLQwGLgzP5ztw23nAA0AQrhsjayfhrlvlZ7J" autocomplete="off">
  <div class="alert alert-info">
    Vertical form, inline checkbox
  </div>
  <div class="mb-3">
    <label for="input-9150c3e87197612f44b21167ccf3b1db" class="form-label">Reference Text</label> <input id="input-9150c3e87197612f44b21167ccf3b1db" type="text" class="form-control" name="u3HTqcxjxQ" value="">
  </div>
  <div class="mb-3">
    <div class="form-check mt-1">
      <input id="check-32875bf6a2dc3f7e4dd005dc081398cd" type="checkbox" class="form-check-input" name="PXCsQ2Ti9V"> <label for="check-32875bf6a2dc3f7e4dd005dc081398cd" class="">Inline Check</label>
    </div>
  </div>
  <div class="col-12 text-end">
    <button id="button-cb220d667c9086fc1146cfac55d4637c" class="btn btn-primary" type="submit">Save</button>
  </div>
</form>

As per any other Larastrap parameter, for all elements, if you want to use the inline layout by default you can enforce it once in your configuration file.

<?php

return [
    /* ... */

    'elements' => [
        /* ... */

        'check' => [
            'inline' => true,
        ],

        /* ... */
    ],

    /* ... */
];

options

x-larastrap::checks and x-larastrap::radios act as a single input field, but are actually a collection of organized items. Each item is an "option", enumerated into the options parameter.

@php

$options = ['red' => 'Red', 'green' => 'Green', 'blue' => 'Blue'];

@endphp

<x-larastrap::checks label="Choose Many" :options="$options" />
<x-larastrap::radios label="Choose One" :options="$options" />
<div class="row mb-3">
  <label for="checks-a40ce400a59421e6efbb5a761f670549" class="col-4 col-form-label">Choose Many</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="checkbox" class="btn-check" name="[]" id="checks-a40ce400a59421e6efbb5a761f670549-ee38e4d5dd68c4e440825018d549cb47" autocomplete="off" value="red"> <label class="btn btn-outline-primary" for="checks-a40ce400a59421e6efbb5a761f670549-ee38e4d5dd68c4e440825018d549cb47">Red</label> <input type="checkbox" class="btn-check" name="[]" id="checks-a40ce400a59421e6efbb5a761f670549-d382816a3cbeed082c9e216e7392eed1" autocomplete="off" value="green"> <label class="btn btn-outline-primary" for="checks-a40ce400a59421e6efbb5a761f670549-d382816a3cbeed082c9e216e7392eed1">Green</label> <input type="checkbox" class="btn-check" name="[]" id="checks-a40ce400a59421e6efbb5a761f670549-9594eec95be70e7b1710f730fdda33d9" autocomplete="off" value="blue"> <label class="btn btn-outline-primary" for="checks-a40ce400a59421e6efbb5a761f670549-9594eec95be70e7b1710f730fdda33d9">Blue</label>
    </div>
  </div>
</div>
<div class="row mb-3">
  <label for="radios-fe1111a66cbb771b4ce12224d46def50" class="col-4 col-form-label">Choose One</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="radio" class="btn-check" name="QiK2MUNDZ1" id="radios-fe1111a66cbb771b4ce12224d46def50-ee38e4d5dd68c4e440825018d549cb47" autocomplete="off" value="red"> <label class="btn btn-outline-primary" for="radios-fe1111a66cbb771b4ce12224d46def50-ee38e4d5dd68c4e440825018d549cb47">Red</label> <input type="radio" class="btn-check" name="QiK2MUNDZ1" id="radios-fe1111a66cbb771b4ce12224d46def50-d382816a3cbeed082c9e216e7392eed1" autocomplete="off" value="green"> <label class="btn btn-outline-primary" for="radios-fe1111a66cbb771b4ce12224d46def50-d382816a3cbeed082c9e216e7392eed1">Green</label> <input type="radio" class="btn-check" name="QiK2MUNDZ1" id="radios-fe1111a66cbb771b4ce12224d46def50-9594eec95be70e7b1710f730fdda33d9" autocomplete="off" value="blue"> <label class="btn btn-outline-primary" for="radios-fe1111a66cbb771b4ce12224d46def50-9594eec95be70e7b1710f730fdda33d9">Blue</label>
    </div>
  </div>
</div>

options can be a simple associative array where keys are the HTML values and values are the related labels. But each value in the options can also be an object, holding a few attributes to better describe each item. Among them:

  • label - the label to display
  • id - an optional ID to identify the option in the DOM. Please note: if you specify an ID, it is up to you to grant it is unique within the current page
  • disabled - set true if the option is not selectable
  • hidden - set true to skip rendering of the label but still keep the option within the page. This can be useful to handle some extra option through Javascript
  • button_classes - CSS classes to be added to the button
  • button_attributes - associative array of HTML attributes to be assigned to the button
@php

$options = [
    'first' => (object) [
        'label' => 'First',
        // This is intentionally broken, as the radio button will change the
        // checkbox having the same ID (as the $options array is here used to
        // init both components)
        // Be aware of IDs you assign!
        'id' => 'first',
    ],
    'second' => (object) [
        'label' => 'Second',
        'disabled' => true,
    ],
    'third' => (object) [
        'label' => 'Third',
        'button_attributes' => ['data-bs-toggle' => 'tooltip', 'data-bs-title' => 'Sample tooltip'],
    ],
    'fourth' => (object) [
        'label' => 'Fourth',
        'hidden' => true,
    ],
    'fifth' => (object) [
        'label' => 'Fifth',
        'button_classes' => ['text-white', 'btn-danger'],
    ],
];

@endphp

<x-larastrap::checks label="Choose Many" :options="$options" />
<x-larastrap::radios label="Choose One" :options="$options" />
<div class="row mb-3">
  <label for="checks-a8bfa4424c0967014598779848167951" class="col-4 col-form-label">Choose Many</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="checkbox" class="btn-check" name="[]" id="first" autocomplete="off" value="first"> <label class="btn btn-outline-primary" for="first">First</label> <input type="checkbox" class="btn-check" name="[]" id="checks-a8bfa4424c0967014598779848167951-c22cf8376b1893dcfcef0649fe1a7d87" autocomplete="off" value="second"> <label class="btn btn-outline-primary disabled" for="checks-a8bfa4424c0967014598779848167951-c22cf8376b1893dcfcef0649fe1a7d87">Second</label> <input type="checkbox" class="btn-check" name="[]" id="checks-a8bfa4424c0967014598779848167951-168909c0b6f1dfbd48f679d47059c1d6" autocomplete="off" value="third"> <label class="btn btn-outline-primary" for="checks-a8bfa4424c0967014598779848167951-168909c0b6f1dfbd48f679d47059c1d6" data-bs-toggle="tooltip" data-bs-title="Sample tooltip">Third</label> <input type="checkbox" class="btn-check" name="[]" id="checks-a8bfa4424c0967014598779848167951-6e599f7a2a9186d391be4537f105be98" autocomplete="off" value="fourth"> <input type="checkbox" class="btn-check" name="[]" id="checks-a8bfa4424c0967014598779848167951-0abdfd715970bd0ef7d5574daa0e6d0b" autocomplete="off" value="fifth"> <label class="btn btn-outline-primary text-white btn-danger" for="checks-a8bfa4424c0967014598779848167951-0abdfd715970bd0ef7d5574daa0e6d0b">Fifth</label>
    </div>
  </div>
</div>
<div class="row mb-3">
  <label for="radios-d5d4506486c5c92aa13454fb8d17ed78" class="col-4 col-form-label">Choose One</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="radio" class="btn-check" name="B5TW5kfrLZ" id="first" autocomplete="off" value="first"> <label class="btn btn-outline-primary" for="first">First</label> <input type="radio" class="btn-check" name="B5TW5kfrLZ" id="radios-d5d4506486c5c92aa13454fb8d17ed78-c22cf8376b1893dcfcef0649fe1a7d87" autocomplete="off" value="second"> <label class="btn btn-outline-primary disabled" for="radios-d5d4506486c5c92aa13454fb8d17ed78-c22cf8376b1893dcfcef0649fe1a7d87">Second</label> <input type="radio" class="btn-check" name="B5TW5kfrLZ" id="radios-d5d4506486c5c92aa13454fb8d17ed78-168909c0b6f1dfbd48f679d47059c1d6" autocomplete="off" value="third"> <label class="btn btn-outline-primary" for="radios-d5d4506486c5c92aa13454fb8d17ed78-168909c0b6f1dfbd48f679d47059c1d6" data-bs-toggle="tooltip" data-bs-title="Sample tooltip">Third</label> <input type="radio" class="btn-check" name="B5TW5kfrLZ" id="radios-d5d4506486c5c92aa13454fb8d17ed78-6e599f7a2a9186d391be4537f105be98" autocomplete="off" value="fourth"> <input type="radio" class="btn-check" name="B5TW5kfrLZ" id="radios-d5d4506486c5c92aa13454fb8d17ed78-0abdfd715970bd0ef7d5574daa0e6d0b" autocomplete="off" value="fifth"> <label class="btn btn-outline-primary text-white btn-danger" for="radios-d5d4506486c5c92aa13454fb8d17ed78-0abdfd715970bd0ef7d5574daa0e6d0b">Fifth</label>
    </div>
  </div>
</div>

As Lists

x-larastrap::checklist and x-larastrap::radiolist are alternative components, where options are rappresented as horizontal rows instead of a x-larastrap::btngroup .

@php

$options = ['red' => 'Red', 'green' => 'Green', 'blue' => 'Blue'];

@endphp

<x-larastrap::radiolist label="Choose One" :options="$options" />
<x-larastrap::checklist label="Choose Many" :options="$options" />
<div class="row mb-3">
  <label for="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b" class="col-4 col-form-label">Choose One</label>
  <div class="col-8">
    <div class="form-control-plaintext">
      <div class="form-check">
        <input class="form-check-input" type="radio" name="BFMxBXMWEK" id="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b-ee38e4d5dd68c4e440825018d549cb47" value="red"> <label class="form-check-label" for="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b-ee38e4d5dd68c4e440825018d549cb47">Red</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="BFMxBXMWEK" id="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b-d382816a3cbeed082c9e216e7392eed1" value="green"> <label class="form-check-label" for="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b-d382816a3cbeed082c9e216e7392eed1">Green</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="BFMxBXMWEK" id="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b-9594eec95be70e7b1710f730fdda33d9" value="blue"> <label class="form-check-label" for="radiolist-d2d960c7fc2b13705f51e7b95e48fd7b-9594eec95be70e7b1710f730fdda33d9">Blue</label>
      </div>
    </div>
  </div>
</div>
<div class="row mb-3">
  <label for="checklist-707757ff4f13da1444361d49fa575d55" class="col-4 col-form-label">Choose Many</label>
  <div class="col-8">
    <div class="form-control-plaintext">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="[]" id="checklist-707757ff4f13da1444361d49fa575d55-ee38e4d5dd68c4e440825018d549cb47" value="red"> <label class="form-check-label" for="checklist-707757ff4f13da1444361d49fa575d55-ee38e4d5dd68c4e440825018d549cb47">Red</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="[]" id="checklist-707757ff4f13da1444361d49fa575d55-d382816a3cbeed082c9e216e7392eed1" value="green"> <label class="form-check-label" for="checklist-707757ff4f13da1444361d49fa575d55-d382816a3cbeed082c9e216e7392eed1">Green</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="[]" id="checklist-707757ff4f13da1444361d49fa575d55-9594eec95be70e7b1710f730fdda33d9" value="blue"> <label class="form-check-label" for="checklist-707757ff4f13da1444361d49fa575d55-9594eec95be70e7b1710f730fdda33d9">Blue</label>
      </div>
    </div>
  </div>
</div>

With Models

Other variants permit to use objects (eventually: Eloquent models) as options within a checks list or radio buttons set. Those are

  • x-larastrap::checks-model
  • x-larastrap::radios-model
  • x-larastrap::checklist-model
  • x-larastrap::radiolist-model
@php

$users = App\Models\User::inRandomOrder()->take(3)->get();

@endphp

<x-larastrap::radios-model label="Select a User" :options="$users" />
<x-larastrap::checks-model label="Select Many Users" :options="$users" />
<x-larastrap::radiolist-model label="Select a User" :options="$users" />
<x-larastrap::checklist-model label="Select Many Users" :options="$users" />
<div class="row mb-3">
  <label for="radios-07838fbda094c813a3fc164455a7680d" class="col-4 col-form-label">Select a User</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="radio" class="btn-check" name="WNbqb5tDEx" id="radios-07838fbda094c813a3fc164455a7680d-24f662cef6848793fb8116a0138de356" autocomplete="off" value="1"> <label class="btn btn-outline-primary" for="radios-07838fbda094c813a3fc164455a7680d-24f662cef6848793fb8116a0138de356">Prof. Ethan Schmitt III</label> <input type="radio" class="btn-check" name="WNbqb5tDEx" id="radios-07838fbda094c813a3fc164455a7680d-21f6586462220d0f798d3db1a00afce4" autocomplete="off" value="8"> <label class="btn btn-outline-primary" for="radios-07838fbda094c813a3fc164455a7680d-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label> <input type="radio" class="btn-check" name="WNbqb5tDEx" id="radios-07838fbda094c813a3fc164455a7680d-53104404aa0e6a2086f4c8e3554bb287" autocomplete="off" value="6"> <label class="btn btn-outline-primary" for="radios-07838fbda094c813a3fc164455a7680d-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label>
    </div>
  </div>
</div>
<div class="row mb-3">
  <label for="checks-f857d3d400194ee5e55bbe5948f994ad" class="col-4 col-form-label">Select Many Users</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="checkbox" class="btn-check" name="[]" id="checks-f857d3d400194ee5e55bbe5948f994ad-24f662cef6848793fb8116a0138de356" autocomplete="off" value="1"> <label class="btn btn-outline-primary" for="checks-f857d3d400194ee5e55bbe5948f994ad-24f662cef6848793fb8116a0138de356">Prof. Ethan Schmitt III</label> <input type="checkbox" class="btn-check" name="[]" id="checks-f857d3d400194ee5e55bbe5948f994ad-21f6586462220d0f798d3db1a00afce4" autocomplete="off" value="8"> <label class="btn btn-outline-primary" for="checks-f857d3d400194ee5e55bbe5948f994ad-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label> <input type="checkbox" class="btn-check" name="[]" id="checks-f857d3d400194ee5e55bbe5948f994ad-53104404aa0e6a2086f4c8e3554bb287" autocomplete="off" value="6"> <label class="btn btn-outline-primary" for="checks-f857d3d400194ee5e55bbe5948f994ad-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label>
    </div>
  </div>
</div>
<div class="row mb-3">
  <label for="radiolist-c5e61b847258afa3e7fe3205c4c7ebab" class="col-4 col-form-label">Select a User</label>
  <div class="col-8">
    <div class="form-control-plaintext">
      <div class="form-check">
        <input class="form-check-input" type="radio" name="KmKaySp6v0" id="radiolist-c5e61b847258afa3e7fe3205c4c7ebab-24f662cef6848793fb8116a0138de356" value="1"> <label class="form-check-label" for="radiolist-c5e61b847258afa3e7fe3205c4c7ebab-24f662cef6848793fb8116a0138de356">Prof. Ethan Schmitt III</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="KmKaySp6v0" id="radiolist-c5e61b847258afa3e7fe3205c4c7ebab-21f6586462220d0f798d3db1a00afce4" value="8"> <label class="form-check-label" for="radiolist-c5e61b847258afa3e7fe3205c4c7ebab-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="KmKaySp6v0" id="radiolist-c5e61b847258afa3e7fe3205c4c7ebab-53104404aa0e6a2086f4c8e3554bb287" value="6"> <label class="form-check-label" for="radiolist-c5e61b847258afa3e7fe3205c4c7ebab-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label>
      </div>
    </div>
  </div>
</div>
<div class="row mb-3">
  <label for="checklist-ff11d598f3c835cf059954b10477d891" class="col-4 col-form-label">Select Many Users</label>
  <div class="col-8">
    <div class="form-control-plaintext">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="[]" id="checklist-ff11d598f3c835cf059954b10477d891-24f662cef6848793fb8116a0138de356" value="1"> <label class="form-check-label" for="checklist-ff11d598f3c835cf059954b10477d891-24f662cef6848793fb8116a0138de356">Prof. Ethan Schmitt III</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="[]" id="checklist-ff11d598f3c835cf059954b10477d891-21f6586462220d0f798d3db1a00afce4" value="8"> <label class="form-check-label" for="checklist-ff11d598f3c835cf059954b10477d891-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="[]" id="checklist-ff11d598f3c835cf059954b10477d891-53104404aa0e6a2086f4c8e3554bb287" value="6"> <label class="form-check-label" for="checklist-ff11d598f3c835cf059954b10477d891-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label>
      </div>
    </div>
  </div>
</div>

The -model variants are able to set their own value accordingly to the Eloquent relationships of the reference entity (the one assigned as obj of the parent x-larastrap::form ), as long as their name matches the attribute to which the relationship itself is exposed.

@php

// In this example, the User model has a "boss" relationship defined as
//
// public function boss()
// {
//     return $this->belongsTo(User::class);
// }
//
// and a "friends" relationship defined as
//
// public function friends()
// {
//     return $this->belongsToMany(User::class);
// }

$ref = App\Models\User::has('boss')->inRandomOrder()->first();
$bosses = App\Models\User::doesntHave('boss')->orderBy('name', 'asc')->get();
$users = App\Models\User::orderBy('name', 'asc')->get();

@endphp

<x-larastrap::form :obj="$ref">
    <x-larastrap::radios-model name="boss" :label="sprintf('Select a Boss for %s', $ref->name)" :options="$bosses" />
    <x-larastrap::checklist-model name="friends" :label="sprintf('Select friends of %s', $ref->name)" :options="$users" />
</x-larastrap::form>
<form id="form-7f6ffaa6bb0b408017b62254211691b5" class="" method="post" name="form-7f6ffaa6bb0b408017b62254211691b5">
  <input type="hidden" name="_token" value="7aLiLLQwGLgzP5ztw23nAA0AQrhsjayfhrlvlZ7J" autocomplete="off">
  <div class="row mb-3">
    <label for="radios-de7e21815aec5e6477b6836049dd95e8" class="col-4 col-form-label">Select a Boss for Mr. Randall Hyatt</label>
    <div class="col-8">
      <div class="btn-group" role="group">
        <input type="radio" class="btn-check" name="boss" id="radios-de7e21815aec5e6477b6836049dd95e8-0baa4bc5b018acf635cb12e812bea244" autocomplete="off" value="7" checked> <label class="btn btn-outline-primary" for="radios-de7e21815aec5e6477b6836049dd95e8-0baa4bc5b018acf635cb12e812bea244">Amaya Beer</label> <input type="radio" class="btn-check" name="boss" id="radios-de7e21815aec5e6477b6836049dd95e8-c9e46a9f63a408e8ceea4a9786acc0b8" autocomplete="off" value="9"> <label class="btn btn-outline-primary" for="radios-de7e21815aec5e6477b6836049dd95e8-c9e46a9f63a408e8ceea4a9786acc0b8">Carolyne Bradtke</label> <input type="radio" class="btn-check" name="boss" id="radios-de7e21815aec5e6477b6836049dd95e8-972db9ba6ce3ee53cf3313b79593e937" autocomplete="off" value="10"> <label class="btn btn-outline-primary" for="radios-de7e21815aec5e6477b6836049dd95e8-972db9ba6ce3ee53cf3313b79593e937">Dr. Gardner Medhurst</label> <input type="radio" class="btn-check" name="boss" id="radios-de7e21815aec5e6477b6836049dd95e8-53104404aa0e6a2086f4c8e3554bb287" autocomplete="off" value="6"> <label class="btn btn-outline-primary" for="radios-de7e21815aec5e6477b6836049dd95e8-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label> <input type="radio" class="btn-check" name="boss" id="radios-de7e21815aec5e6477b6836049dd95e8-21f6586462220d0f798d3db1a00afce4" autocomplete="off" value="8"> <label class="btn btn-outline-primary" for="radios-de7e21815aec5e6477b6836049dd95e8-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label>
      </div>
    </div>
  </div>
  <div class="row mb-3">
    <label for="checklist-29cb03713af42a602d362dd70b4be80f" class="col-4 col-form-label">Select friends of Mr. Randall Hyatt</label>
    <div class="col-8">
      <div class="form-control-plaintext">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-3f51aa5990b818921059a68ad0efc32f" value="4" checked> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-3f51aa5990b818921059a68ad0efc32f">Aiden Osinski</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-0baa4bc5b018acf635cb12e812bea244" value="7"> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-0baa4bc5b018acf635cb12e812bea244">Amaya Beer</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-c9e46a9f63a408e8ceea4a9786acc0b8" value="9"> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-c9e46a9f63a408e8ceea4a9786acc0b8">Carolyne Bradtke</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-85620ea94cfa584cd2d7de970e07f91c" value="3" checked> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-85620ea94cfa584cd2d7de970e07f91c">Dr. Darrin Hamill</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-972db9ba6ce3ee53cf3313b79593e937" value="10" checked> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-972db9ba6ce3ee53cf3313b79593e937">Dr. Gardner Medhurst</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-53104404aa0e6a2086f4c8e3554bb287" value="6" checked> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-21f6586462220d0f798d3db1a00afce4" value="8"> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-9e28615787830d2372846c8d264e608a" value="5" checked> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-9e28615787830d2372846c8d264e608a">Mr. Cyril Adams</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-218711070b310b3ed0c9153acec8cb68" value="2"> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-218711070b310b3ed0c9153acec8cb68">Mr. Randall Hyatt</label>
        </div>
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="friends[]" id="checklist-29cb03713af42a602d362dd70b4be80f-24f662cef6848793fb8116a0138de356" value="1"> <label class="form-check-label" for="checklist-29cb03713af42a602d362dd70b4be80f-24f662cef6848793fb8116a0138de356">Prof. Ethan Schmitt III</label>
        </div>
      </div>
    </div>
  </div>
  <div class="col-12 text-end">
    <button id="button-4d42d8160b4ab3aa68018114a40bc5f7" class="btn btn-primary" type="submit">Save</button>
  </div>
</form>

For -model variants it is assumed that models into the options collection have an "id" and a "name" attribute to be used (respectively: as the value and the label of each item).

If your models have a different structure, or you want to display different labels, it is possible to pass a translateCallback parameter with a function to translate your actual content: it has to accept a parameter (the model to be translated) and must return an array with two elements (the value and the label of the final selectable option).

@php

$users = App\Models\User::inRandomOrder()->take(3)->get();
$translate = fn($obj) => [$obj->id, $obj->email];

@endphp

<x-larastrap::radiolist-model label="Select a User" :options="$users" :translateCallback="$translate" />
<div class="row mb-3">
  <label for="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e" class="col-4 col-form-label">Select a User</label>
  <div class="col-8">
    <div class="form-control-plaintext">
      <div class="form-check">
        <input class="form-check-input" type="radio" name="sgokuoSCn3" id="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e-3816d563547e428d17156a3d9ef5f70a" value="1"> <label class="form-check-label" for="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e-3816d563547e428d17156a3d9ef5f70a">ashly77@example.org</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="sgokuoSCn3" id="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e-4ca7027f3f6d7b8cf9add7f296a180f4" value="10"> <label class="form-check-label" for="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e-4ca7027f3f6d7b8cf9add7f296a180f4">pokon@example.com</label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="sgokuoSCn3" id="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e-6ade9766d95ce2a7d2d06697eaebb4b5" value="5"> <label class="form-check-label" for="radiolist-e952aa8cdfae6ae0158d3e7f13f85f6e-6ade9766d95ce2a7d2d06697eaebb4b5">henri86@example.net</label>
      </div>
    </div>
  </div>
</div>

The -model variants have also an extra_options parameter to define other options aside those collected in the options . This is useful to add a "void" item to be choosen by the user.

@php

$users = App\Models\User::inRandomOrder()->take(3)->get();

@endphp

<x-larastrap::radios-model label="Select a User" :options="$users" :extra_options="[0 => 'None']" value="0" />
<div class="row mb-3">
  <label for="radios-ea21ab453dc051fa0ca885734ceec2a0" class="col-4 col-form-label">Select a User</label>
  <div class="col-8">
    <div class="btn-group" role="group">
      <input type="radio" class="btn-check" name="iHF8m8OMPR" id="radios-ea21ab453dc051fa0ca885734ceec2a0-6adf97f83acf6453d4a6a4b1070f3754" autocomplete="off" value="0" checked> <label class="btn btn-outline-primary" for="radios-ea21ab453dc051fa0ca885734ceec2a0-6adf97f83acf6453d4a6a4b1070f3754">None</label> <input type="radio" class="btn-check" name="iHF8m8OMPR" id="radios-ea21ab453dc051fa0ca885734ceec2a0-21f6586462220d0f798d3db1a00afce4" autocomplete="off" value="8"> <label class="btn btn-outline-primary" for="radios-ea21ab453dc051fa0ca885734ceec2a0-21f6586462220d0f798d3db1a00afce4">Miss Earnestine Lowe</label> <input type="radio" class="btn-check" name="iHF8m8OMPR" id="radios-ea21ab453dc051fa0ca885734ceec2a0-972db9ba6ce3ee53cf3313b79593e937" autocomplete="off" value="10"> <label class="btn btn-outline-primary" for="radios-ea21ab453dc051fa0ca885734ceec2a0-972db9ba6ce3ee53cf3313b79593e937">Dr. Gardner Medhurst</label> <input type="radio" class="btn-check" name="iHF8m8OMPR" id="radios-ea21ab453dc051fa0ca885734ceec2a0-53104404aa0e6a2086f4c8e3554bb287" autocomplete="off" value="6"> <label class="btn btn-outline-primary" for="radios-ea21ab453dc051fa0ca885734ceec2a0-53104404aa0e6a2086f4c8e3554bb287">Dr. Pasquale Borer IV</label>
    </div>
  </div>
</div>