Created
March 11, 2019 07:03
-
-
Save ericamigo/2afb3603843e3b243a883b6cc6729a4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Requests; | |
use Illuminate\Foundation\Http\FormRequest; | |
class CustomValidationRequest extends FormRequest | |
{ | |
/** | |
* Determine if the user is authorized to make this request. | |
* | |
* @return bool | |
*/ | |
public function authorize() | |
{ | |
return auth()->check(); | |
} | |
protected function validationData() | |
{ | |
$this['already_exists'] = 0; | |
// query if student already exists | |
$student = Query::here()->first(); | |
if ($student) { | |
$this['already_exists'] = 1; | |
} | |
return $this->all(); | |
} | |
/** | |
* Get the validation rules that apply to the request. | |
* | |
* @return array | |
*/ | |
public function rules() | |
{ | |
return [ | |
'already_exists' => 'required|in:0', | |
]; | |
} | |
public function messages() | |
{ | |
return [ | |
'already_exists.in' => 'Student is already enrolled', | |
]; | |
} | |
} |
pwede kaayo sir @kharlmostwanted
gikan na sa iyang FormRequest parent class
puro na sya overrides sir pati kanang messages()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kanang validationData() sa request jud na na function no? so pwede nako ibutang tanan custom validation nako draa?