امین
3 سال پیش توسط امین مطرح شد
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