ReakyMark
1 year ago
129
2
Laravel

Why validator only return validation.required not the message in res/lang/xx/validator.php ?

Posted 1 year ago by ReakyMark

this is my code at backend

$validator = Validator::make(
            $req->all(),
            [
                'title'        => 'required',
                'url'          => 'nullable',
                'upload_slide' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
            ]
);

return redirect()->back()
            ->withErrors($validator)
            ->withInput();

this is my code at Frontend

@if ($errors->any())  
    <?php
        $errorMessage = '';
        $i = 1;
        //var_dump($errors->all());
    ?>
    @foreach ($errors->all() as $error )
       <?php $errorMessage .= $i++.': '.$error .'<br>'; ?>
    @endforeach
    {!! $createMessage->make($errorMessage, 'alert-danger') !!}
@endif

code above result in 1: validation.required ....etc what is my problem ?

if i want show message i have to custom it with

$message = [
            'title.required' => 'Please fill Title',
            'url.required' => 'Please fill url',
            'upload_slide.required' => 'Please add image to upload',
            'upload_slide.mimes'    => 'Extension not supported',
            'upload_slide.max'    => 'File is bigger than 2MB'
        ];

code above result in 1: Please fill Title ....etc

Please sign in or create an account to participate in this conversation.