-
app/Providers/AppServiceProvider.php
Open in GitHubuse Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { // public function register() { Blade::directive('errorClass', function ($field) { $ifStatement = "if(session()->has('errors') && session('errors')->has(${field}))"; return "<?php {$ifStatement} echo 'is-invalid'; ?>"; }); } // }
-
resources/views/components/inputs/text.blade.php
Open in GitHub@props(['key']) <div class="input-group mb-3"> <input {{ $attributes }} wire:model.defer="{{ $key }}" type="text" name="{{ $key }}" class="form-control @errorClass($key)" placeholder="{{ trans("validation.attributes.$key") }}" > <x-inputs.fa fontAwesome="fa-edit" /> <x-inputs.error field="{{ $key }}" /> </div>
-
resources/views/components/inputs/dropdown.blade.php
Open in GitHub@props(['options', 'key', 'textField']) <div class="input-group mb-3"> <select {{ $attributes }} wire:model.defer="{{ $key }}" name="{{ $key }}" class="form-control @errorClass($key)" value="{{ old($key) }}" placeholder="{{ trans("validation.attributes.$key") }}" > <option value="">-- select --</option> @foreach($options as $option) <option value="{{ $option->id }}">{{ $option->$textField }}</option> @endforeach </select> <x-inputs.fa fontAwesome="fa-cogs" /> <x-inputs.error field="{{ $key }}" /> </div>