Skip to content

Instantly share code, notes, and snippets.

@ericamigo
Created March 11, 2019 07:03
Show Gist options
  • Select an option

  • Save ericamigo/2afb3603843e3b243a883b6cc6729a4c to your computer and use it in GitHub Desktop.

Select an option

Save ericamigo/2afb3603843e3b243a883b6cc6729a4c to your computer and use it in GitHub Desktop.
<?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',
];
}
}
@kharlmostwanted
Copy link
Copy Markdown

kanang validationData() sa request jud na na function no? so pwede nako ibutang tanan custom validation nako draa?

@admbrnldz
Copy link
Copy Markdown

pwede kaayo sir @kharlmostwanted

@ericamigo
Copy link
Copy Markdown
Author

gikan na sa iyang FormRequest parent class

@admbrnldz
Copy link
Copy Markdown

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