dongzhi6087 2016-09-20 07:02
浏览 5

基于其他列表laravel 5显示来自数据库的数据

I want to display data from spesific column users table, let say uiprv column. and uiprv same as id from provinsi table.

This is User table image:

enter image description here

and this is provinsi table:

enter image description here

and now, I've succesfully display data from database but just show "31". 31 is uiprv column from users table, it same thing with id from provinsi table. the question is, how to display data not just 31 , but it can be DKI JAKARTA . like in nama_provinsi at provinsi table .

How should I write code in my controller for this. Thanks in Advance.

  • 写回答

4条回答 默认 最新

  • dongqiuge5435 2016-09-20 07:29
    关注

    Add this in your App/User.php

    /**
     * Returns the province of the user
     *
     * @return 
     */
    public function province()
    {
        // Province is your model related to Provinsi table
        return $this->belongsTo('App\Province');
    }
    

    From what you've written,

    Relationship between User to Province is Many to one.

    Reference - https://laravel.com/docs/5.3/eloquent-relationships

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch