Skip to content

Instantly share code, notes, and snippets.

@skadimoolam
Last active February 8, 2020 17:03
Show Gist options
  • Save skadimoolam/f2afa4a2a036ce62e0280be056d164de to your computer and use it in GitHub Desktop.
Save skadimoolam/f2afa4a2a036ce62e0280be056d164de to your computer and use it in GitHub Desktop.
Customizable form partials for Laravel - https://laravelcollections.com
@php
$d = $d ?? null; // default value
@endphp
<div class="form-group row">
<label for="{{ $n }}" class="col-sm-4 col-form-label text-md-right"><b>{{ $l }}</b></label>
<div class="col-md-8">
<input id="{{ $n }}" type="checkbox" class="form-control" name="{{ $n }}" value="1" @if(old($n, $d) == '1') checked @endif>
@if ($errors->has($n))
<small class="text-danger">{{ $errors->first($n) }}</small>
@endif
</div>
</div>
<form method="POST" action="{{ route("users.store") }}">
@method("POST")
@csrf
@include('form.input', ['n' => 'name', 'l' => 'Name', 'r' => true, 'd' => 'Default Name'])
@include('form.input', ['n' => 'email', 'l' => 'Email', 'r' => true, 'a' => true, $t => 'email']) @include('form.submit', ['l' => 'Create Link'])
@include('form.submit', ['l' => 'Create new User'])
</form>
@php
$t = $t ?? 'text'; // type of input
$d = $d ?? null; // default value
$p = $p ?? 'Enter ' . $l; // placeholder text
$r = $r ?? false; // is required or not
$a = $a ?? false; // is autofocused or not
@endphp
<div class="form-group row">
<label for="{{ $n }}" class="col-sm-4 col-form-label text-md-right"><b>{{ $l }}</b></label>
<div class="col-md-8">
<input id="{{ $n }}" type="{{ $t }}" class="form-control" name="{{ $n }}" value="{{ old($n, $d) }}" placeholder="{{ $p }}" @if($r) required @endif @if($a) autofocus @endif>
@if ($errors->has($n))
<small class="text-danger">{{ $errors->first($n) }}</small>
@endif
</div>
</div>
@php
$d = $d ?? null; // default value
$r = $r ?? false; // is required or not
$a = $a ?? false; // is autofocused or not
@endphp
<div class="form-group row">
<label for="{{ $n }}" class="col-sm-4 col-form-label text-md-right"><b>{{ $l }}</b></label>
<div class="col-md-8">
<select id="{{ $n }}" class="form-control" name="{{ $n }}" @if($r) required @endif @if($a) autofocus @endif>
<option value="">-- SELECT --</option>
@foreach($i as $item)
@if($item == old($n, $d))
<option value="{{ $item }}" selected>{{ $item }}</option>
@else
<option value="{{ $item }}">{{ $item }}</option>
@endif
@endforeach
</select>
@if ($errors->has($n))
<small class="text-danger">{{ $errors->first($n) }}</small>
@endif
</div>
</div>
<div class="row">
<div class="form-group mx-auto mb-0">
<button type="submit" class="btn btn-primary">{{ $l }}</button>
</div>
</div>
@php
$d = $d ?? null; // default value
$p = $p ?? 'Enter ' . $l; // placeholder text
$r = $r ?? false; // is required or not
$a = $a ?? false; // is autofocused or not
@endphp
<div class="form-group row">
<label for="{{ $n }}" class="col-sm-4 col-form-label text-md-right"><b>{{ $l }}</b></label>
<div class="col-md-8">
<textarea id="{{ $n }}" class="form-control" name="{{ $n }}" placeholder="{{ $p }}" @if($r) required @endif @if($a) autofocus @endif>{{ old($n, $d) }}</textarea>
@if ($errors->has($n))
<small class="text-danger">{{ $errors->first($n) }}</small>
@endif
</div>
</div>
@andruu
Copy link

andruu commented Jan 18, 2019

Should release a package ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment