Reputation: 23
I just started working with laravel
and I was wondering if there is a way to put links/buttons in your validation lines.
For example I created a basic registration page (followed the laravel
docs). When somebody is trying to register an account with a wrong email (only specific email account will be registered directly, the others will be put on a waiting list), the user will get a little error message saying that they will be put on a waiting list and a button if they would like to be on this waiting list.
Here is my code:
Auth/AuthController
protected function validator(array $data)
{
return Validator::make($data, [
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'username' => 'required|max:50|unique:users',
'email' => 'required|email|max:255|unique:users|regex:/@student\.test\.be$/',
'password' => 'required|confirmed|min:6',
]);
}
Validation.php //Custom Validation Language Lines
'email' => [
'unique' => 'This email is already already registered',
'required' => 'Email is required.',
'regex' => 'some text <button>want to be on the waitinglist?</button>',
],
And then there is a basic register view with a form and the error messages
@if (count($errors) > 0)
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}
@endforeach
</div>
@endif
Upvotes: 2
Views: 33
Reputation: 1345
I think you'd be better of doing it in your view file, something like the following:
@if (array_key_exists('regex', $errors->get('email')))
some text <button>want to be on the waitinglist?</button>
@endif
EDIT:
You can also change {{ $error }}
to {!! $error !!}
to display HTML properly.
@if (count($errors) > 0)
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{!! $error !!}
@endforeach
</div>
@endif
Upvotes: 1