drip5880 2018-10-26 04:04
浏览 163
已采纳

Laravel从外键获取数据

I have two table one is called Submission one called AssignSubmission

Submission belongTo AssignSubmission

public function assignsubmission()
{
    return $this->belongsTo('App\AssignSubmission');
}

AssignSubmissionhasManySubmission

public function submissions()
{
    return $this->hasMany('App\Submission');
}

They are linked with foreign keys In AssignSubmission has id, user_id and submission_id the foreign key is submission_id. In Submission table, it has id, user_id and file, url etc

in AssignSubmission submission_id -> links to -> Submission id. I have assigned different submission to 2 users. enter image description here

How can I get data from the foreign key? I want to display the url or file in the view

enter image description here

  • 写回答

5条回答 默认 最新

  • duanboxue3422 2018-10-26 04:29
    关注

    If you have a Submission object $submission already,

    $submission->assignSubmission->url will give you the url.

    It converts to camalCase for property name.

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

报告相同问题?

悬赏问题

  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥15 vba参数转c++ SAFEARRAY
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题
  • ¥15 unity3d机械臂