Skip to content

Extended form requests #1070

@lauren-spideyweb

Description

@lauren-spideyweb

Scribe version

5.9.0

Your question

We have a 'base' form request that is extended by a few others which is used like below

/**
	 * @var string
	 */
	protected string $type;

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array<string, ValidationRule|array|string>
	 */
	public function rules(): array
	{
		$rules = [
			'first_run' => 'boolean|prohibits:last_update_date',
			'last_update_date' => 'nullable|date_format:Y-m-d H:i:s',
		];
		if (isset($this->type)) {
			$rules['last_update_date'] = $rules['last_update_date'] . '|prohibits:'.$this->type;
			$rules[$this->type] = 'nullable|array|prohibits:last_update_date';
		}

		return $rules;
	 }

with another request using it as per below

class QuestionUpdateRequest extends BaseUpdateRequest
{
	protected function prepareForValidation()
	{
		$this->type = 'questions';
	}

    public function bodyParameters(): array
    {
		return array_merge(parent::bodyParameters(), [
            'questions' => [
                'description' => 'Array of question ID`s the application already has installed along with the dates last modified',
                'example' => [
                    '1' => '2024-08-10 12:00:01',
                    '149' => '2024-07-28 10:40:01',
                    '3051' => '2024-09-31 15:10:06'
                ]
            ],
        ]);
    }
}

Only the first defined set of rules get output, not the type specific ones or inside the if statement. How can I get these all to appear?

Docs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions