0

routes/api.php routes/api.php

Controllers/UserController.php UserController

User Model

usermodel

Migration

migration

Тест в POSTMAN введите сюда описание изображения

Вот сообщение об ошибке:

 Response:{
       {
          "message":"The given data was invalid.",
          "errors":{
             "name":[
                "The name field is required."
             ],
             "surname":[
                "The surname field is required."
             ],
             "patronymic":[
                "The patronymic field is required."
             ],
             "sex":[
                "The sex field is required."
             ],
             "birthday":[
                "The birthday field is required."
             ],
             "country":[
                "The country field is required."
             ],
             "city":[
                "The city field is required."
             ],
             "telephone":[
                "The telephone field is required."
             ],
             "email":[
                "The email field is required."
             ],
             "password":[
                "The password field is required."
             ]
          }
       }
    }
 class UserController extends Controller
 {
 public function signup (Request $request) {      

     $this->validate($request->all(), [
         'name' => 'required',
         'surname' => 'required',
         'patronymic'  => 'required',
         'sex' => 'required',
         'birthday' => 'required|date',
         'country' => 'required',
         'city' => 'required',
         'telephone' => 'required',
         'email' => 'required|email|unique:users',
         'password' => 'required|max:32'
     ]);

     $user = new User([
         'name' => $request->input('name'),
         'surname' => $request->input('surname'),
         'patronymic' => $request->input('patronymic'),
         'sex' => $request->input('sex'),
         'birthday' => $request->input('birthday'),
         'country' => $request->input('country'),
         'city' => $request->input('city'),
         'telephone' => $request->input('telephone'),
         'email' => $request->input('email'),
         'password' => bcrypt($request->input('password'))
     ]);

     $user->save();

     return response()->json([
         'message' => 'Successfully, new User created!!!'
     ], 201);
 }

}

   class User extends Authenticatable
{
 use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'surname', 'patronymic', 'sex', 'birthday', 'country', 'city', 'telephone', 'email', 'password'
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

}

3
  • Переведите вопрос на русский, пожалуйста.
    – Byulent
    27 окт 2017 в 17:36
  • 2
    .. и в виде текста.
    – Visman
    27 окт 2017 в 17:37
  • 3
    + вся текстовая информация (код, json), должна быть в вопросе в виде текста, а не скриншотов.
    – insolor
    27 окт 2017 в 17:37

1 ответ 1

1

Во первых, в теле запроса отправляется json объект, поэтому валидатор жалуется на отсутсвие полей.

Во вторых, json из тела запроса можно забрать с помощью Input::all();

И в третьих, валидацию нужно переделать, так как выше написал, у тебя не POST параметры идут, а в теле запроса json объект.

upd Совсем ступил, если хочешь чтобы все так же осталось в коде, то нужно сменить просто сам запрос: введите сюда описание изображения

Выбираешь вкладку Body там form-data и заполняешь как на картинке поля

1
  • Большое спасибо, все по полочкам объяснил! 27 окт 2017 в 18:14

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.