Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Created October 23, 2017 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niraj-shah/445326a459dcf10a89267519122213d3 to your computer and use it in GitHub Desktop.
Save niraj-shah/445326a459dcf10a89267519122213d3 to your computer and use it in GitHub Desktop.
Custom validation and error message in Laravel 5
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
protected $redirectTo = '/dashboard';
/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get the password reset validation rules.
*
* @return array
*/
protected function getResetValidationRules()
{
return [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:8|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).+$/',
];
}
/**
* Get the password reset validation messages.
*
* @return array
*/
protected function getResetValidationMessages()
{
return [
'password.regex' => 'Password must contain at least 1 lower-case and capital letter, a number and symbol.'
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment