Search code examples
phplaravelorchid

Laravel Orchid getting data from custom blade layout


Basic orchid tables really bad in terms if interactivity so i created a table using blade template like this:

<table id=permissions'>
    <thead>
      <tr>
        <td>{{ __('Permission') }}</td><td>{{ __('Status') }}</td><td class='hide'></td>
      </tr>
    </thead>
    <tbody>
      @foreach($permissions as $permission)
        <tr>
          <td>{{ $permission['description'] }}</td>
          <td><input type='checkbox' @if($permission['active']) checked @endif></td>
          <td class='hide'>{{ $permission['slug'] }}</td>
        </tr>
      @endforeach
    </tbody>
  </table>
  {!!
    \Orchid\Screen\Actions\Button::make(__('Save'))
      ->method('save')
  !!}

Data from table not existing in request when i call "save()" method (the call itself is fine). Is there any way to solve this? I figured orchid filling request using "name" property of orchid's element, but i do not now how to implement it on my html table


Solution

  • Found a solution myself. The trick is: data you want from table must be a value of input field and that field must have unique name. Like this

    <td>{{ $field['description'] }}</td>
    <td><input name={{ $field['slug'].'-status' }} type='checkbox' @if($field['active']) checked @endif></td>
    <td style='display:none'><input name={{ $field['slug'] }} value={{ $field['slug'] }}></td>
    

    In $request variable it wil be looking like:

    [
     'permission.1.slug' => slug.value
     'permission.1.slug-status' => 'on' (wont be present if checkbox is emty)
    ]
    

    In my case on server it looks like "dump" of fields, but at least it working now.