How can I remove an error message from a MessageBag
?
I've been trying to remove a specific element from the message array that MessageBag
uses without any luck.
I'm getting the same error message twice.
@if($errors->has('undefined'))
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>Failure.</h4>
{{ $errors->first('undefined') }}
</div>
<?
// $messages = $errors->getMessages();
$messages = $errors->toArray();
unset($messages['undefined']);
?>
@endif
@if($errors->any())
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>Error!</h4>
{{ $errors->first() }}
</div>
@endif
Edit
I have done something like this and it seems to work.
<?
$messages = $errors->toArray();
?>
@if(array_key_exists('undefined', $messages))
<?
$message_array = $messages['undefined'];
$message = $message_array[0];
unset($messages['undefined']);
?>
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>Failure.</h4>
{{ $message }}
</div>
@endif
<?
foreach ($messages as $error => $error_array) {
?>
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>Error!</h4>
{{ $error_array[0] }}
</div>
<?
}
?>
But my question still remains? Why is this happening in first place?
Does it has to do with the Session? I know that the errors
variable it is stored in the Session.
MessageBag
,and why this isn't possible since they are stored in an array. Thnx for the answer! – Cristincristina