Example of Form requests in JuanDMeGon/Laravel-from-Scratch

File app/Http/Requests/ProductRequest.php (link to Github)
use Illuminate\Foundation\Http\FormRequest;

class ProductRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'title' => ['required', 'max:255'],
            'description' => ['required', 'max:1000'],
            'price' => ['required', 'min:1'],
            'stock' => ['required', 'min:0'],
            'status' => ['required', 'in:available,unavailable'],
            'images.*' => ['nullable', 'image'],
        ];
    }

    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            if ($this->stock == 0 && $this->status == 'available') {
                $validator->errors()->add('stock', 'If available must have stock');
            }
        });
    }
}

Additional resources on Form requests: