من میخوام با استفاده از sender_id یک کاربر تو یه جدول به اسم اش تو جدول user برسم
الان این روش درسته؟
public function index(){
$contacts = Contact::select('sender_id')->where('receiver_id',auth::id())->orderBy('updated_at','DESC');
dd($contacts->user->name);
}
اینم روابطی که نوشتم:
public function user(){
return $this->belongsTo(user::class);
}
public function contact(){
return $this->hasMany(Contact::class);
}
این هم جدول contact هست:
$table->id();
$table->integer('receiver_id');
$table->foreignId('sender_id')->constrained('users')->cascadeOnUpdate()->cascadeOnDelete();
$table->timestamps();
$table->tinyInteger('seen');
خطایی که میگیرم:
Property [user] does not exist on the Eloquent builder instance
اولین نفری باشید که به این پرسش کمک میکند و مسیر حل مشکل را باز میکند.
اولین پاسخ را بنویسیدشاید پاسخ شما همینجا باشد