G
G
GaserV2016-11-09 23:19:56
Laravel
GaserV, 2016-11-09 23:19:56

Why is the variable unknown?

Such situation. I do verification of users on a box. Why does it say that $user is undefined in the Mail line?
Z.Y. The data is coming in and the arrays are not empty.

public function signup(Request $request)
    {
        $user = array(

            'firstname' => $request->firstname,
            'lastname' => $request->lastname,
            'middlename' => $request->middlename,
            'gender' => $request->gender,
            'email' => $request->email,
            'password' => $request->password,
            'password_confirm' => $request->password_confirm,
            'confirm_code' => encrypt(str_random(30)),

        );

        $rules = array(
            'firstname'  => 'required',
            'lastname'   => 'required',
            'middlename' => 'required',
            'email'      => 'required|email|unique:users',
            'password'   => 'required',
            'password_confirm' => 'required|same:password'
        );

        $validator = Validator::make($user,$rules);

        if($validator->fails())
            return response() -> json(array(
                'fail' => true,
                'errors' => $validator->getMessageBag()->toArray()
            ));
        else {
            $user['password'] = bcrypt($user['password']);

            $data = array(
                'username' => $user['firstname'],
                'confirm_code' => $user['confirm_code'],
            );

            if (User::create($user)) {
                Mail::send('email_verify', $data, function($message) {
                    $message->to($user['email'], $user['firstname'])
                        ->subject('Подтверждение регистрации');
                });  

                return response() -> json(array(
                    'success' => 'Вы успешно зарегистрировались. Проверьте ваш почтовый ящик и активируйте аккаунт.'
                ));
            }
            else {
                return 'false';
            }
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Wolf, 2016-11-09
@GaserV

Most likely by the fact that you use the so-called. callback function (or in Russian - a closure function), and its scope is usually strictly limited.
I think the following would fix the situation:
Here are some details.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question