Kareimovich's avatar

Laravel vue validation

Hi everyone I have My validator here and in my form when I let the name field empty I don't get required error

           $validator = Validator::make($request->all(), [
                'name' => 'required',
              ]);

    if ($validator->fails()) {
        return $this->sendError('error validation', $validator->errors());
    }

i just get it when i change

        'name' => 'required',

To

        'name' => 'required|10',

Note i tried

        'name' => 'required|max:8',

when the field is empty and i get this error

    The name may not be greater than 8 characters.

My Vue

                               <b-col sm="8">
                                    <b-form-input v-model="Newnews.name" type="text" name="name"></b-form-input>
                                    <p v-text="errors.get('name')" class="errorr"></p>

                                </b-col>
0 likes
5 replies
bobbybouwmann's avatar

How is your Vue component build up? It might be that you send an empty string whenever it is empty? Can you share some more information from what you send from vue to the backend?

bobbybouwmann's avatar

@kareimovich What is the value of Editednews? If that has a value and you post that, of course the validation won't kick in!

Kareimovich's avatar

@bobbybouwmann the problem is in the create and i'm not the one how write this vue but this is what i can understand please help

   Newnews: {},

createnews() { this.loading = true; let news = this.Newnews; let formData = new FormData();

  formData.append("name", news.name);
  formData.append("place", news.place);
  formData.append("date", news.date);
    news.img && news.img.name
    ? formData.append("img", news.img, news.img.name)
    : "";


  axios
    .post("api/news", formData)
    .then(resp => {
      this.onSuccess(resp.data.message);
      this.updateTable();
    })
    .catch(error => {
      this.errors.record(error.response.data.data);
      this.loading = false;
    });
  this.loading = false;
},
bobbybouwmann's avatar

@kareimovich I can't really help you if you don't understand your own code! Right now I can see that news is initialized with this.Newnews. You have to figure out what is in there.

You can also see in the developer tools of the browser what data is being posted in the network tab. That might help as well for you!

Please or to participate in this conversation.