Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tomi's avatar
Level 8

Request Rule is not catching the errors

namespace App\Http\Requests;

class ActionRequest extends Request { protected $dates = [ 'timestamp', 'timestamp_end' ];

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    $rules = [
        'timestamp' => 'required',
        'user_id' => 'required',
        'name' => 'required',
        'prm_action_type_id' => 'required'
    ];

    return $rules;
}

public function all($keys = null)
{

    $result = parent::all($keys);

    $types = app('\App\Repositories\System\Action\TypeRepository');

    $actionType = $types->find($result['prm_action_type_id']);

    if (!isset($actionType->appointment) && array_key_exists('timestamp_end', $result)) {
        unset($result['timestamp_end']);
    }

    return $result;
}

}

So i expected that if i have aRequest Class with rules and i override the all function the Request gets validated when i call ->all(). Instead i get undefined index prm_action_type_id (that is ok, cause i didnt even sent it to the server, but i expected to be catched by the Rules.)

I think i got here something wrong?

0 likes
2 replies
bobbybouwmann's avatar
Level 88

Mmh it should not actually call all before validating the request. I've been looking into the code but I never see the all method being called there. So it seems that something weird is happening here, since it tried to access a field it doesn't have.

Your request class should catch that the field is not available! Are you sure you used the ActionRequest class in your controller?

1 like
Tomi's avatar
Level 8

Yap i do use the ActionRequest. Cuase i get the undefined index error for prm_action_type_id. This is realy strange.

Please or to participate in this conversation.