Hi there,
Not sure why this one didn't attract any responses. Maybe because the answer was so easy to work out, most people thought, 'He'll get there in the end.'
Well, I did! I thought I'd put this up here in case anybody else gets stuck on a similar issue and comes across this post in their Googling.
This is some of what I put in my ThingRequest.php file:
...
use Laravel\Spark\ThingType;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
class ThingRequest extends FormRequest
...
public function validator()
{
$thingCatId = FormRequest::get('thing_cat_id');
$thingCatName = ThingType::where('id', $thingCatId)->value('name');
$required = ThingType::where('id', $thingCatId)->value('purchased');
if ($required == 'y') {
return Validator::make($this->all(), [
'thing_cat_id' => 'required',
'purchase_date' => 'required|date_format:d/m/Y',
'notes' => 'max:255',
], $this->messages());
}
else {
return Validator::make($this->all(), [
'thing_cat_id' => 'required',
'notes' => 'max:255',
], $this->messages());
}
}
If anyone reads this and thinks, 'I know a more elegant solution to this!' please add it.
With kind regards,
Mark