DEV Community

Talemul Islam
Talemul Islam

Posted on

2

MessageBag in Laravel - Laravel tips

This article is only for laravel developer.

MessageBag is a great tools in laravel php framework to send error message in previous page. In few days ago i fall in a problem to send some error message to view page. But i can't use it on validation of laravel and send error. i have several check of work. i have to overwrite MessageBag. so i use this simple syntax like below.

$message = new MessageBag([
'field_name' => ['Invalid input, Please try again.'],
]);

And send it on like this.

return redirect()->back()->withInput()->withErrors($message);
I have already have a view page where i want to show after submit this.

<div class="form-group{{ $errors->has('field_name') ? ' has-error' : '' }}">
<h3 class="payment-tittle">Insert your Input here</h3>
<input class="is_required validate account_input form-control {{ ($errors->has('field_name'))?"input-error":"" }}"
type="tel" name="otp" value="{{ old('field_name') }}" required>
@if ($errors->has('field_name'))
<span class="help-block"> {{ $errors->first('field_name') }} </span>
@endif
</div>

But i suggest all of you that use laravel validation process. But this process can be help you.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️