Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@andruu 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