我有一個名爲的用戶和配置文件。在配置文件表中有一列名爲userID.Now我想這列取值從用戶表的id
。我已經完成數據庫關係的一部分。根據我的問題找到了滿意的答案。如何從用戶表中檢索用戶ID?
通過Laravel.I我是新的方式,到目前爲止已經試過
用戶模型:
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $table ="users";
protected $fillable = [
'userName', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function userProfile(){
return $this->hasOne('App\Profile');
}
}
簡介型號:
class Profile extends Model
{
//
protected $table = "profiles";
public $fillable = ["firstName","lastName","middleName","DOB","gender","featuredProfile","email","phone","summary","profilePic"];
public function user(){
return $this->belongsTo('App\User');
}
}
,我試圖檢索userID
與{{$profile->userID}}
。我真的不知道在哪裏是公關會徽和如何做到這一點?
它給了我一個錯誤'試圖獲得非對象的屬性。 –
'$ profile-> user-> id;'因爲'user'表的db列是'id'而不是'userid' – Junaid