Skip to content

Instantly share code, notes, and snippets.

@tonysm
Last active April 8, 2022 02:18
Show Gist options
  • Save tonysm/343a0de2a3c1de36c306905778f5957c to your computer and use it in GitHub Desktop.
Save tonysm/343a0de2a3c1de36c306905778f5957c to your computer and use it in GitHub Desktop.
Combining Turbo Frames and Streams
<x-app-layout title="New Invitations">
<h1>New Invitations!</h1>
<form action="{{ route('invitations.store') }}" method="POST">
<div id="invitations"></div>
<button type="submit">Invite</button>
</form>
<x-turbo-frame id="create_trigger_invitations">
<x-turbo-stream target="invitations" action="append">
@php $invitationIndex = request('invitation', 0); @endphp
<div>
<div>
<label for="invitations_{{ $invitationIndex }}_name">Name</label>
<input type="text" name="invitations[{{ $invitationIndex }}][name]" placeholder="Jane Doe" id="invitations_{{ $invitationIndex }}_name" />
</div>
<div>
<label for="invitations_{{ $invitationIndex }}_email">Email</label>
<input type="email" name="invitations[{{ $invitationIndex }}][email]" placeholder="jane.doe@example.com" id="invitations_{{ $invitationIndex }}_email" />
</div>
<br />
</div>
</x-turbo-stream>
<a href="{{ route('invitations.create', ['invitation' => ++$invitationIndex]) }}">Add More</a>
</x-turbo-frame>
</x-app-layout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment