Larastan: Undefined method setAttributeNames() when creating Instance via the Laravel validator() helper

Created on 13 Aug 2020  路  1Comment  路  Source: nunomaduro/larastan

  • Larastan Version: 0.6.0
  • --level used: 3

Description

When creating a validator instance via the validator() helper, the following error is thrown:
Call to an undefined method Illuminate\Contracts\Validation\Factory|Illuminate\Contracts\Validation\Validator::setAttributeNames().

In code I set a custom attribute name based on the localization used for the application.

Laravel code where the issue was found

    public function process(Request $request): RedirectResponse
    {
        $validator = validator($request->all(), [
            'message' => 'required',
        ]);

        $validationAttributeNames = [
            'message' => trans('g.label.message'),
        ];

        $validator->setAttributeNames($validationAttributeNames);
        $validator->validate();

        // Further method implementations
     }

I hope you can help me out!

Kind Regards!

enhancement

Most helpful comment

Hi,

Weird, this error shouldn't happen on level 3. I thought errors related to union types are started reporting on level 7.

Anyways, this is a feature request for a new extension for validator helper function.

For now you can use

/** @var \Illuminate\Contracts\Validation\Validator $validator */
$validator = validator($request->all(), [
    'message' => 'required',
]);

// Rest of the code

to resolve it.

I'll try to implement the new extension later.

>All comments

Hi,

Weird, this error shouldn't happen on level 3. I thought errors related to union types are started reporting on level 7.

Anyways, this is a feature request for a new extension for validator helper function.

For now you can use

/** @var \Illuminate\Contracts\Validation\Validator $validator */
$validator = validator($request->all(), [
    'message' => 'required',
]);

// Rest of the code

to resolve it.

I'll try to implement the new extension later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iNviNho picture iNviNho  路  3Comments

danielcosta picture danielcosta  路  4Comments

mariomka picture mariomka  路  4Comments

fico7489 picture fico7489  路  3Comments

hailwood picture hailwood  路  4Comments