0

Подскажите почему ен проходит такой запрос на создание новой записи?

   $userInBase = User::where('email', $$request->email)->first();
            if ($userInBase){
                $user = User::create(['email' => $request->email, 'name' => $request->email, 'role_id' => 2]);
                if ($user)
                {
                    $attributes = UsersAttributes::create(['user_id' => $user->id, 'phone' => $request->phone, 'username' => $request->name]);
                    if ($attributes)
                    {
                        return 'ok';
                    }
                }
            }

2 ответа 2

2

Есть опечатка. Дважды написал $ перед переменной request.

User::where('email', $$request->email)->first();

3
  • это убрал, но все ровно не работает
    – Aslero
    14 сен 2018 в 7:24
  • вот что у меня подключено <?php namespace App\Http\Controllers; use App\User; use App\UsersAttributes; use App\UserSubjects; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB;
    – Aslero
    14 сен 2018 в 7:27
  • Попробуй получать содержимое значений используя метод $request->get('имя поля'), то есть $request->get('email') и т.д. 15 сен 2018 в 16:57
0

Вначале проверьте пришло ли значение

$email = null;
if($request->has('email')) {
  $email = $request->input('email');
}

Ваш ответ

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

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