Troubleshooting
Common Issues
Q: Why isn't my form field populating with the model value?
A: Check the value resolution priority order:
- Is there old input in the session? (After validation failure, old input takes precedence)
- Is
considerRequest()enabled and is there request data? - Did you pass an explicit value parameter?
- Is the model actually set? Use
Form::getModel()to verify - Is the attribute name correct and accessible on the model?
// Debug value resolution
@if(Form::getModel())
Model is set: {{ get_class(Form::getModel()) }}
@endif
// Check what value the form builder is using
{{ Form::getValueAttribute('field_name') }}
Q: How do I access nested model relationships in forms?
A: Use dot notation:
{{ Form::model($user, ['route' => 'profile.update']) }}
{{-- Access nested relationships --}}
{{ Form::text('profile.bio') }}
{{ Form::text('company.address.city') }}
{{ Form::close() }}
Make sure the relationships are loaded (use $user->load('profile', 'company.address')).
Q: My form mutators aren't working
A: Verify the following:
- You've added the
FormAccessibletrait to your model - The method name follows the pattern:
form{AttributeName}Attribute - The attribute name matches exactly (case-sensitive)
- You're using
Form::model()for model binding
// Correct mutator pattern
public function formBirthDateAttribute($value)
{
return $value ? $value->format('Y-m-d') : null;
}
Q: Can I disable CSRF protection for a specific form?
A: CSRF protection is automatic. If you need to disable it (not recommended), you can:
- Remove the token manually (not ideal): Don't use
Form::open(), write raw HTML - Exclude the route in
VerifyCsrfTokenmiddleware - Add the route to
$exceptarray in the CSRF middleware
Better approach: Keep CSRF enabled and handle it properly in your JavaScript/AJAX calls.
Q: Old input isn't showing after validation failure
A: This usually means the session isn't configured properly:
- Verify session configuration in
config/session.php - Check that the session middleware is active for your route
- Ensure you're redirecting with
withInput():return back()->withInput() - Verify the FormBuilder has access to the session (dependency injection handles this automatically)
Q: How do I create custom form components?
A: Register them in a service provider:
// In AppServiceProvider or custom provider
public function boot()
{
Form::component('bsText', 'components.form.bootstrap-text', ['name', 'value', 'attributes']);
}
See the Custom Components section for full examples.
Q: Date inputs aren't formatting correctly
A: DateTime objects are automatically formatted for HTML5 date inputs. If using custom formats:
// The form builder handles these automatically:
{{ Form::date('date', $model->date) }} // Expects Y-m-d
{{ Form::datetime('datetime', $model->datetime) }} // RFC3339 format
{{ Form::datetimeLocal('datetime', $model->datetime) }} // Y-m-d\TH:i
// If you need custom formatting, use a form mutator:
public function formCustomDateAttribute($value)
{
return $value ? $value->format('m/d/Y') : null;
}
Q: How do I add custom validation display?
A: Combine with Laravel's error handling:
{{ Form::text('email', null, ['class' => 'form-control ' . ($errors->has('email') ? 'is-invalid' : '')]) }}
@error('email')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
Q: Can I use this with Vue/React components?
A: Yes, but you have two approaches:
- Server-side rendering: Use Form Builder in Blade, then hydrate with JavaScript
- API approach: Build forms in JavaScript, use Laravel for API endpoints only
For SPAs, consider using the Form Builder primarily for initial page loads or progressive enhancement.