dongwoqin7034 2017-11-27 05:22
浏览 67
已采纳

laravel在尝试进行更新时返回null

I am trying to do an update with my data but when I try to pass $object to another view it is returning me null value. I did a dd($id) and it return me the id that I wanted but if I do a dd($object) return me null. I have check similar question to this such as Laravel Eloquent::Find() returning NULL with an existing ID but still doesn't work. Everyone say that the problem comes from the database, but I don't understand which part. Can anyone help me? Thanks a lot

VerificationController:

 public function editVerify($id){
    $object = Verification::find($id);
    dd($object);
    return view('editVerify', compact('object'));
}

Verification Model:

     public function personal_infos() {
        return $this->belongsTo("App\PersonalInfo", "id", 'user_id');
}

PersonalInfo model:

                public function verifications() {
return $this->hasOne('App\Verification','user_id');

}

This is what it look like in the database(some value are NULL while some contain data) enter image description here enter image description here Verification table:

  Schema::create('verifications', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
              $table->string('Nationality');
            $table->string('identity_type');
            $table->string('residential_status');
            $table->string('NRIC_check');
            $table->string('nric_number1');
            $table->string('blacklist');
            $table->string('whiteCard');
            $table->string('educational_cert');
            $table->string('WSQ_cert');
            $table->integer('user_id')->unsigned(); 
            $table->foreign('user_id')->references('id')->on('personal_infos');
            $table->timestamps();
        });
  • 写回答

2条回答 默认 最新

  • douxunchen3498 2017-11-27 06:05
    关注

    When we use Eloquent find(), find method works with primary key. As you are using find() method to fetch data, it expects id as its parameter but you are looking to fetch records with user_id. So here is my solution-

    $v=Verification::where('user_id','=',$id)->first();
    

    or make user_id column your primary key.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算