Removing the laravel error messages once the text field is clicked - php

Currently I'm showing my form validation error messages in the front end blade under the relevant field.
But the messages are there until the user resubmit the form, they wont removed.
I want to hide each error message once the user clicks on the field (or in the most user friendly way).
This is form code for my register blade,
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('sentence.First Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="last_name" class="col-md-4 col-form-label text-md-right">{{ __('sentence.Last Name') }}</label>
<div class="col-md-6">
<input id="last_name" type="text" class="form-control #error('name') is-invalid #enderror" name="last_name" value="{{ old('name') }}" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('sentence.E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="text" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" autofocus>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="moblie" class="col-md-4 col-form-label text-md-right">{{ __('Mobile') }}</label>
<div class="col-md-6">
<input id="mobile_1" type="tel" class="form-control #error('mobile') is-invalid #enderror" name="mobile" value="{{ old('mobile') }}" style="min-width: 330px;" autofocus>
#error('mobile')
<br/>
<span class="help-block" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="username" class="col-md-4 col-form-label text-md-right">{{ __('sentence.Username') }}</label>
<div class="col-md-6">
<input id="username" type="text" class="form-control #error('username') is-invalid #enderror" name="username" value="{{ old('username') }}" autofocus>
#error('username')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('sentence.Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" >
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('sentence.Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" >
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('sentence.Register') }}
</button>
</div>
</div>
</form>

I think the most user-friendly way is to have client-side validation,
Security: Server-side validation
User friendly: Client-side validation
For client-side, you can use jQuery, In your case:
<script>
jQuery( document ).ready(function() {
// event for click on input (also you can use click)
//better to change form to .yourFormClass
$('form input[type=text]').focus(function(){
// get selected input error container
$(this).siblings(".invalid-feedback").hide();
});
});
</script>
Add this code before closing body tag,(Don't forget to use the jQuery library ),
Hope it helps

Related

Only some values are editing with a form Laravel 8

I am using a form and I don't know why I can edit with it the values except in the fields apellido and cedula.
I am using the same logic in all the form fields so I dunno what can be causing it.
I'm gonna post the code of the view, controller, and model.
View
#extends('layouts.app')
#section('content')
<div class="container">
<h1>Editar Médico</h1>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('medico.update', $medico) }}">
#csrf
#method('PUT')
<div class="form-group row">
<label for="nombre" class="col-md-4 col-form-label text-md-right">{{ __('Nombre') }}</label>
<div class="col-md-6">
<input id="nombre" type="text" class="form-control #error('nombre') is-invalid #enderror" name="nombre" value="{{ $medico->nombre}}" required autocomplete="nombre" autofocus>
#error('nombre')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="apellido" class="col-md-4 col-form-label text-md-right">{{ __('Apellido') }}</label>
<div class="col-md-6">
<input id="apellido" type="text" class="form-control #error('apellido') is-invalid #enderror" name="apellido" value="{{ $medico->apellido}}" required autocomplete="apellido" autofocus>
#error('apellido')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="cedula" class="col-md-4 col-form-label text-md-right">{{ __('Cédula') }}</label>
<div class="col-md-6">
<input id="cedula" type="text" class="form-control #error('cedula') is-invalid #enderror" name="apellido" value="{{ $medico->cedula}}" required autocomplete="cedula" autofocus>
#error('cedula')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('Email') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ $medico->email}}" required autocomplete="email" autofocus>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="telefono" class="col-md-4 col-form-label text-md-right">{{ __('Teléfono') }}</label>
<div class="col-md-6">
<input id="telefono" type="text" class="form-control #error('telefono') is-invalid #enderror" name="telefono" value="{{ $medico->telefono}}" required autocomplete="telefono" autofocus>
#error('telefono')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="direccion" class="col-md-4 col-form-label text-md-right">{{ __('Dirección') }}</label>
<div class="col-md-6">
<input id="direccion" type="text" class="form-control #error('direccion') is-invalid #enderror" name="apellido" value="{{ $medico->direccion}}" required autocomplete="direccion" autofocus>
#error('direccion')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="ciudadResi" class="col-md-4 col-form-label text-md-right">{{ __('Ciudad de Residencia') }}</label>
<div class="col-md-6">
<input id="ciudadResi" type="text" class="form-control #error('ciudadResi') is-invalid #enderror" name="apellido" value="{{ $medico->ciudadResi}}" required autocomplete="ciudadResi" autofocus>
#error('ciudadResi')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="fechaNacimiento" class="col-md-4 col-form-label text-md-right">{{ __('Fecha de Nacimiento') }}</label>
<div class="col-md-6">
<input id="fechaNacimiento" type="date" class="form-control #error('fechaNacimiento') is-invalid #enderror" name="fechaNacimiento" value="{{ $medico->fechaNacimiento}}" required autocomplete="fechaNacimiento" autofocus>
#error('fechaNacimiento')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="genero" class="col-md-4 col-form-label text-md-right">{{ __('Genero') }}</label>
<div class="col-md-6">
<input id="genero" type="text" class="form-control #error('genero') is-invalid #enderror" name="genero" value="{{ $medico->genero}}" required autocomplete="genero" autofocus>
#error('genero')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Editar') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Controller
public function updateMedico(Request $request, $id) {
$medico = Persona::findOrFail($id);
$medico->fill($request->all());
if($medico ->save()) {
return redirect()->route('personaMostrarMedicos');
} else {
return redirect()->route('medico.edit');
}
}
Model
public $timestamps =false;
protected $fillable = [
'nombre',
'apellido',
'cedula',
'email',
'telefono',
'direccion',
'ciudadResi',
'fechaNacimiento',
'genero',
'estado',
'idTipoPersona'
];
I have no idea what could be wrong because only those 2 fields I mention are the ones I can't update, the other ones are fine.
In case it can helps this is also my database model
After using dd($request->all()); in the controller this is the output
What I have in the form before clicking the update button and the output of dd($request->all())
I am not sure if this is the problem, but you have 2 name="apellido", check cedula, it has that name, so that is wrong.
Remember that when you send a form, the way to get the value is going to use the name property and not the id as that is pure CSS.
Change this:
<input id="cedula" type="text" class="form-control #error('cedula') is-invalid #enderror" name="apellido" value="{{ $medico->cedula}}" required autocomplete="cedula" autofocus>
To this:
<input id="cedula" type="text" class="form-control #error('cedula') is-invalid #enderror" name="cedula" value="{{ $medico->cedula }}" required autocomplete="cedula" autofocus>
You have two inputs with the same name apellido this is why it isn't working properly.
Change this -
<input id="cedula" type="text" class="form-control #error('cedula') is-invalid #enderror" name="apellido" value="{{ $medico->cedula}}" required autocomplete="cedula" autofocus>
To this -
<input id="cedula" type="text" class="form-control #error('cedula') is-invalid #enderror" name="cedula" value="{{ $medico->cedula}}" required autocomplete="cedula" autofocus>
It should be working then.

419 Page Expired in laravel 7

I have error 419 | Page Expired when i login in my website, i alrady use #csrf in my form.
what can i do to fix this problem ?
this is my login.php file
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
try clearing the browser cache as well as laravel with php artisan cache:clear.
Sometime 419 is due to stale cache.

Laravel displays error 419 page expired on register

Whenever I try to register it says 419 page expired. I have try cleaning cache and even checked other answers such as adding #csrf in the form but nothing worked. It says the same for login as well.
My code: (register.blade.php)
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="new-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
My code: (login.blade.php)
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
#if (Route::has('password.request'))
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
I do have the #csrf after form starts (as suggested in other answers) but this didn't work either. How can I fix this error? If you need any more details or code please let me know I will upload it.

laravel 7 eye hidden

i try to add hide eye in password in laravel project in register. i find code in codepen but when i add
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password"></span>
Register
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-12">
<h1 style="border-bottom: solid yellow;"><strong>Formulaire d'inscription</strong></h1>
<div class="card-body">
<form method="POST" action="{{ route('register') }}" enctype="multipart/form-data">
#csrf
<h3><strong>Vos identifiants</strong></h3>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">Adresse mail</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Mot de passe</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="new-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
<div class="input-group-addon">
<i class="fa fa-eye-slash" aria-hidden="true"></i>
</div>
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">Confirmation mot de passe</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<h3><strong>Informations personnelles</strong></h3>
<div class="form-group row">
<label for="sex" class="col-md-4 col-form-label text-md-right">Civilité</label>
<div class="col-md-1">
<div class="form-check">
<input class="form-check-input" type="radio" name="sexe" id="exampleRadios1" value="M" checked>
<label class="form-check-label" for="exampleRadios1">
Male
</label>
</div>
</div>
<div class="col-md-1">
<div class="form-check">
<input class="form-check-input" type="radio" name="sexe" id="exampleRadios2" value="F">
<label class="form-check-label" for="exampleRadios2">
Female
</label>
</div>
</div>
</div>
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">Prénom</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="firstname" class="col-md-4 col-form-label text-md-right">Nom</label>
<div class="col-md-6">
<input id="firstname" type="text" class="form-control #error('firstname') is-invalid #enderror" name="firstname" value="{{ old('firstname') }}" required autocomplete="firstname" autofocus>
#error('firstname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="address" class="col-md-4 col-form-label text-md-right">Adresse</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control #error('address') is-invalid #enderror" name="address" value="{{ old('address') }}" required autocomplete="address" autofocus>
#error('address')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="city" class="col-md-4 col-form-label text-md-right">Ville</label>
<div class="col-md-6">
<input id="city" type="text" class="form-control #error('city') is-invalid #enderror" name="city" value="{{ old('city') }}" required autocomplete="city" autofocus>
#error('city')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="zipcode" class="col-md-4 col-form-label text-md-right">Code postale</label>
<div class="col-md-6">
<input id="zipcode" type="text" class="form-control #error('zipcode') is-invalid #enderror" name="zipcode" value="{{ old('zipcode') }}" required autocomplete="zipcode" autofocus>
#error('zipcode')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="phone" class="col-md-4 col-form-label text-md-right">Numéro de téléphone</label>
<div class="col-md-6">
<input id="phone" type="text" class="form-control #error('phone') is-invalid #enderror" name="phone" value="{{ old('phone') }}" required autocomplete="phone" autofocus>
#error('phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="birthday" class="col-md-4 col-form-label text-md-right">Date de naissance</label>
<div class="col-md-6">
<input id="birthday" type="date" class="form-control #error('birthday') is-invalid #enderror" name="birthday" value="{{ old('birthday') }}" required autocomplete="birthday" autofocus>
#error('birthday')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="pseudo" class="col-md-4 col-form-label text-md-right">Nom d'utilisateur (pseudo)</label>
<div class="col-md-6">
<input id="pseudo" type="text" class="form-control #error('pseudo') is-invalid #enderror" name="pseudo" value="{{ old('pseudo') }}" required autocomplete="pseudo" autofocus>
#error('pseudo')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="avatar" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="avatar" type="file" class="form-control #error('avatar') is-invalid #enderror" name="avatar" autocomplete="avatar" autofocus>
#error('avatar')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-4">
<div class="g-recaptcha"
data-sitekey="{{env('GOOGLE_RECAPTCHA_KEY')}}">
</div>
<span role="alert" class="invalid-feedback d-block">
#error('g-recaptcha-response')
<strong>{{ $errors->first('g-recaptcha-response') }}</strong>
#enderror
</span>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Crée mon compte
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#show_hide_password a").on('click', function(event) {
event.preventDefault();
if($('#show_hide_password input').attr("type") == "text"){
$('#show_hide_password input').attr('type', 'password');
$('#show_hide_password i').addClass( "fa-eye-slash" );
$('#show_hide_password i').removeClass( "fa-eye" );
}else if($('#show_hide_password input').attr("type") == "password"){
$('#show_hide_password input').attr('type', 'text');
$('#show_hide_password i').removeClass( "fa-eye-slash" );
$('#show_hide_password i').addClass( "fa-eye" );
}
});
});
</script>
#endsection
#section('scripts')
<script src='https://www.google.com/recaptcha/api.js'></script>
#endsection
not have something, i try to add code from there :
https://codepen.io/Qanser/pen/dVRGJvm but its not work for me i think i do something not good someone can help me add eye? Nothing appears, it's been 2 hours already I'm on it I can't take it anymore XD Someone
you can see my screen shot in this link : ibb.co/W2kQTj8
Have mercy on a noob help me XD
make sure that the page layouts.app that you extend have the link to fa eye class like one bellow
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
</head>
<body>
<i class="fa fa-eye"></i>
</body>
</html>

Laravel - login messages

I'm currently working on Laravel 5.8 version and I'm using Laravel make:auth option. That created me login and registration and all I did i add a phone number. So this is how it is looking in my register.blade.php :
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="new-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<div class="form-group row">
<label for="phone" class="col-md-4 col-form-label text-md-right">{{ __('Phone Number') }}</label>
<div class="col-md-6">
<input id="phone" type="phone" class="form-control" name="phone" required>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
So this section:
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
shows me span message if email has already been taken. So how can I do that #error('phone') for my phone? I coded in my RegisterController.php that my phone my be unique:users?
Please help me with this #error message!
This will check User Phone Number Like Email. It Will Allocate Unique user Phone Number
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'phone' => 'required|unique:users,phone'
]);
}
For Displaying Errors In Register Blade
#error('phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
You need to add something like this to RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'phone' => 'required'
]);
}

Categories