ValidationException .....
public function rules()
{
return [
'school_number' => 'required',
'school_name' => 'required'
];
}
These FormValidations are used to validate forms (figures). When it throws a validation exception, it's because you are going to that route, but are not POSTing data according to the rules you setup
But where is the route where you are injecting this?
// some SchoolController perhaps ?
public function store(SchoolRequest $request)
{
$school = School::create($request->all());
return redirect()->back()->withMessage('The school has been created');
}
This is basically how you should use the requests.... on the other side of a POST route, where it validates the data or redirects the user back to the page they came from with a bunch of error messages about missing data.
Also, why the extra boilerplate code?:
public function findOrFail($id)
{
$school = $this->school->find($id);
if (!$school) {
throw ValidationException::withMessages(['message' => trans('school.could_not_find')]);
}
return $school;
}
// could simply be:
public function findOrFail($id)
{
return $this->school->findOrFail($id);
}