Enclose

"Enclose" is a peculiar type of element provided by Larastrap: similar to a Form, it acts as a logical container for other elements without providing any actual HTML markup.

@php
$obj = App\Models\User::inRandomOrder()->first();
@endphp

<x-larastrap::enclose :obj="$obj">
    <x-larastrap::text name="name" readonly squeeze />
    <x-larastrap::email name="email" squeeze />
</x-larastrap::enclose>
<input id="input-62f251b988074248ec32ec553e9611da" type="text" class="form-control-plaintext" name="name" value="Dr. Pasquale Borer IV" readonly> <input id="input-b354e53ea2b08c8c833567dfa59e8a0f" type="email" class="form-control" name="email" value="everette14@example.org">

His may purpose is to isolate different models within the same logical block. The common use case is: a form with a table involving multiple models at once, each with his own attributes (and his own input fields).

<x-larastrap::form>
    <table class="table">
        @foreach(App\Models\User::inRandomOrder()->take(3)->get() as $user)
            <x-larastrap::enclose :obj="$user">
                <tr>
                    <td><x-larastrap::text name="name" readonly squeeze="true" /></td>
                    <td><x-larastrap::email name="email" npostfix="[]" squeeze="true" /></td>
                </tr>
            </x-larastrap::enclose>
        @endforeach
    </table>
</x-larastrap::form>
<form id="form-c16a5320fa475530d9583c34fd356ef5" class="" method="post" name="form-c16a5320fa475530d9583c34fd356ef5">
  <input type="hidden" name="_token" value="SI5ZwzjHsYentVBCmyFSPZ4h3W8kL9VJanti9BdX">
  <table class="table">
    <tr>
      <td>
        <input id="input-67b35e5cb44bbe4ea237e7a82634883d" type="text" class="form-control-plaintext" name="name" value="Carolyne Bradtke" readonly>
      </td>
      <td>
        <input id="input-b5ca9a643ae5e5650cfb06a22e4016b5" type="email" class="form-control" name="email[]" value="wisoky.dax@example.org">
      </td>
    </tr>
    <tr>
      <td>
        <input id="input-2d8e91d79ab8320207a3d9ec3878d320" type="text" class="form-control-plaintext" name="name" value="Amaya Beer" readonly>
      </td>
      <td>
        <input id="input-63bfd8d2f64dcba29e7127a8f162dfce" type="email" class="form-control" name="email[]" value="vwisozk@example.com">
      </td>
    </tr>
    <tr>
      <td>
        <input id="input-a217750d511026798ac42cd0d16f4915" type="text" class="form-control-plaintext" name="name" value="Dr. Gardner Medhurst" readonly>
      </td>
      <td>
        <input id="input-9eff8c573482960ac8ffdb00e5872a82" type="email" class="form-control" name="email[]" value="pokon@example.com">
      </td>
    </tr>
  </table>
  <div class="col-12 text-end">
    <button id="button-a3d59420ee91b6c4ad016346c73c8188" class="btn btn-primary" type="submit">Save</button>
  </div>
</form>

In the example above, it is important to note the use of npostfix parameter: when the form is submitted, all email addresses have to be serialized into an array and sent to the specified endpoint (the form's action ).

Larastrap