Skip to content

Instantly share code, notes, and snippets.

@hoofdletterj
Last active December 25, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoofdletterj/8447df35767cf961b702d0af9f22fc76 to your computer and use it in GitHub Desktop.
Save hoofdletterj/8447df35767cf961b702d0af9f22fc76 to your computer and use it in GitHub Desktop.
Blade form elements for sharing on create and edit forms
@foreach ($tags as $tag)
<input
type="checkbox"
name="tag[]"
value="{{$tag->id}}"
{{
empty(old())
? (in_array($tag->id, $userTagIDs) ? 'checked' : '')
: (is_array(old('tag')) && in_array($tag->id, old('tag')) ? 'checked' : '')
}}
>
<label for="tag[]">{{$tag->name}}</label>
@endforeach
<input type="hidden" name="is_admin" value="0">
<input type="checkbox" name="is_admin" value="1"
@if ($errors->any())
{{ empty(old('is_admin')) ? '' : 'checked' }}
@else
{{ (($user->is_admin ?? false) == false ? '' : 'checked') }}
@endif
>
<select name="status_id">
<option disabled value="" {{(old('status_id', $user->status_id ?? null)) == null ? 'selected' : ''}}></option>
@foreach ($userStatuses as $status)
<option value="{{$status->id}}" {{(old('status_id', $user->status_id ?? null)) == $status->id ? 'selected' : ''}}>
{{$status->display_name}}
</option>
@endforeach
</select>
<select name="gender">
<option value="" {{ (old('gender', $user->gender ?? null) ) === null ? 'selected' : ''}}></option>
<option value="m" {{ (old('gender', $user->gender ?? null) ) == 'm' ? 'selected' : '' }}>Male</option>
<option value="f" {{ (old('gender', $user->gender ?? null) ) == 'f' ? 'selected' : '' }}>Female</option>
<option value="o" {{ (old('gender', $user->gender ?? null) ) == 'o' ? 'selected' : ''}}>Non-binary</option>
</select>
<textarea name="notes" rows="8">{{ old('notes', $user->notes ?? null ) }}</textarea>
<input type="text" name="first_name" value="{{ old('first_name', $tuseralent->first_name ?? null ) }}">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment