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

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay