Sunday, April 2, 2017

How to return the error validator laravel in string format

In this example code:

 public function test(Request $request) {
    $rule = [
        'name' => 'required'
    ];
    $validator = Validator::make($request->all(), $rule);
    if ($validator->fails()) {
        return $validator->errors(); // <-- String format, not array
    }
    return $request->name;
}

I need that the error be a simple string.

Thanks



via Mer

Advertisement