امین
1 سال پیش توسط امین مطرح شد
0 پاسخ

روابط جداول در لاراول

من میخوام با استفاده از 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


ثبت پرسش جدید

به همدیگه کمک کنیم

به امین کمک کنید تا مشکل خودش را حل کند؛ این‌طور می‌توانیم با هم پیشرفت کنیم.

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام