I'm trying to add a failedValidation() function to a custom Request. I've googled some examples in what I assume are much older Laravel versions (I'm using 9.15), but when I try to add it it gives the error:
Declaration of App\Http\Requests\BasketRequest::failedValidation() must be compatible with Illuminate\Foundation\Http\FormRequest::failedValidation(Illuminate\Contracts\Validation\Validator $validator)
The weird thing is that I can add passedValidation() just fine. So what's the problem? Or rather, how do I fix it, because the framework's code for the validation goes a bit over my head.
Also how can I add additional variables to the return back() that the validation executes out of sight somewhere?
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class BasketRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
protected function passedValidation()
{
dd('passedValidation');
}
protected function failedValidation()
{
dd('failedValidation');
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [];
}
}