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 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突