hasAttributes.php /非法偏移类型中的errorexception



我在存储用户数据时有问题,当用户注册时,我将一半的信息存储在表用户中,而另一半则在另一个表中,当命中寄存器butttom时,我发现该错误,我发现在表用户信息中,用户信息存储了Correctley,但在其他表中没有保存任何保存。

错误

in HasAttributes.php line 818
at HandleExceptions->handleError(2, 'Illegal offset type', 'C:\wamp\www\Menoon1\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php', 818, array()) in HasAttributes.php line 818
at Model->getCasts() in HasAttributes.php line 803
at Model->hasCast('email', array('date', 'datetime')) in HasAttributes.php line 832
at Model->isDateCastable('email') in HasAttributes.php line 565
at Model->isDateAttribute('email') in HasAttributes.php line 525
at Model->setAttribute('email', 'dde@hg.com') in Model.php line 223
at Model->fill(array('email' => 'dde@hg.com')) in Model.php line 145
at Model->__construct(array('email' => 'dde@hg.com')) in Model.php line 268
at Model->newInstance(array('email' => 'dde@hg.com')) in Builder.php line 1030
at Builder->newModelInstance(array('email' => 'dde@hg.com')) in Builder.php line 723
at Builder->create(array('email' => 'dde@hg.com')) in Model.php line 1332
at Model->__call('create', array(array('email' => 'dde@hg.com'))) in Model.php line 1344
at user_emails->create(array('email' => 'dde@hg.com')) in Model.php line 1344
at Model::__callStatic('create', array(array('email' => 'dde@hg.com'))) in RegisterController.php line 94
at user_emails::create(array('email' => 'dde@hg.com')) in RegisterController.php line 94
at RegisterController->create(array('_token' => 'FZqd7Sc3fQRzmaQ0ImXYebzltzkygJsbKpNcZhv4', 'username' => 'vbnm v bnmm', 'email' => 'dde@hg.com', 'password' => '1111111', 'password_confirmation' => '1111111', 'fname' => 'vbn', 'lname' => 'bnm', 'address' => 'bnm', 'membership' => 'Normal', 'pic' => object(UploadedFile))) in RegistersUsers.php line 33
at RegisterController->register(object(Request))
at call_user_func_array(array(object(RegisterController), 'register'), array(object(Request))) in Controller.php line 55
at Controller->callAction('register', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(RegisterController), 'register') in Route.php line 204
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->IlluminateRouting{closure}(object(Request)) in RedirectIfAuthenticated.php line 24
at RedirectIfAuthenticated->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->IlluminateFoundationHttp{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->IlluminateRouting{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\wamp\www\Menoon1\public\index.php') in server.php line 21

用户模式

 public function useremail()
    {
        return $this->hasOne('Appuser_emails');
    }

其他表代码

public function user()
    {
        return $this->belongsTo('AppUser');
    }

registercontroller中的代码

  protected function create(array $data)
    {
      $fileName = 'null';
      Input::file('pic')->store('avatars');
      if (Input::file('pic')->isValid()) {
        $destinationPath = public_path('uploads/files');
        $extension = Input::file('pic')->getClientOriginalExtension();
        $fileName = uniqid().'.'.$extension;
        Input::file('pic')->move($destinationPath, $fileName);
    }
          
        $user= User::create([
            'fname' => $data['fname'],
            'lname' => $data['lname'],
            'address' => $data['address'],
            'username' => $data['username'],         
            'membership' => $data['membership'],
            'pic'=>$fileName,
            'password' => bcrypt($data['password']),
        ]);
        $useremail=user_emails::create(['email'=>$data['email']]);
       // dd($useremail);
        $user->useremail()->save($useremail);
        return $user;
    }

我不知道您的模型,但是如果具有复合键,则收集无法获得属性

尝试

$user->useremail()->save(new UserEmail(['email'=>$data['email']]));

鉴于用户邮件的模型是用户邮件。

混合了您的模型:应该适用于app useremail:

public function user()
{
    return $this->belongsTo('AppUser');
}

和应用程序 user

public function userEmail()
{
    return $this->hasOne('Appuser_emails');
}

为了自己的利益,请注意大会。"用户邮件"成为用户邮件。模型文件成为user.php和useremail.php。您的表"用户"one_answers" user_emails"。因此," user_emails"中的关系应为'user_id'。并做了。

i面对同一问题,它发生了,因为在模型中,我也定义了一个主键,但是在创建表时,它已经在数据库中设置了一个条款。

相关内容

  • 没有找到相关文章

最新更新