2017-11-27 05:22
浏览 65


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


 public function editVerify($id){
    $object = Verification::find($id);
    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) {
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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-


    or make user_id column your primary key.

    打赏 评论
  • duanpu8830 2017-11-27 06:09

    Currently, you are working with find() of Eloquent, and it find record regarding to 'id', in your DB it not exists and it exists in your user_id column!

    So, change query to


    And this gives you result OR change primary key to user_id

    Hope this helps you!

    打赏 评论

相关推荐 更多相似问题