This package is for Laravel only.
You can specify an object as a view argument.
Rescue you from View Arguments Hell.
- For Laravel : run
composer require junichimura/view-args
in your project folder.
<?php
use Junichimura\ViewArgs\FormArgs;
class InputFormArgs extends FormArgs
{
public $label;
public $type;
public $disabled;
public function __construct($label, $type)
{
$this->label = $label;
$this->type = $type;
}
public function disabled($condition = true)
{
$this->disabled = (bool)$condition;
return $this;
}
public static function make($label, $type = 'text')
{
return new static($label, $type);
}
}
{{-- views/sample/input.blade.php --}}
<div class="form-group">
<label>{{ $args['label'] }}</label>
<input class="form-group" name="{{ $args->name }}" type="{{ $args->type }}"
@isset( $args->value ) value="{{ $args->value }}" @endisset
placeholder="{{ $args->placeholder }}"
@if($args->disabled) disabled @endif>
@error( $args->name )
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<?php
// routes/web.php
Route::get('sample', function () {
return view('sample.input', \InputFormArgs::make('Your Email', 'email')
->value('[email protected]')
->placeholder('[email protected]')
->disabled());
});
<div class="form-group">
<label>Your Email</label>
<input class="form-group" name="" type="email" value="[email protected]" placeholder="[email protected]" disabled >
</div>
Laravel-View-Args is open-source software licensed under the MIT license.