यह प्रश्न पहले से ही here से पूछा गया था लेकिन इसे कोई जवाब नहीं मिला। अब मुझे एक ही समस्या का सामना करना पड़ रहा है लेकिन लार्वेल 5.4 में। मेरे पास एक मॉडल Book
है, एक मॉडल ReadingSession
और एक मॉडल Comment
है। एक पुस्तक में कई पढ़ने के सत्र हैं और इसमें कई टिप्पणियां हैं लेकिन रीडिंग सत्र में टिप्पणियां भी हो सकती हैं। तो मैं अपने संबंधों को इस तरह परिभाषित किया है:एक बच्चे मॉडल में एक बहुलक संबंध का उपयोग अनंत अनंत पाश का कारण बनता है?
Book.php
protected $with = [
'author',
'readingSessions',
'userRating',
'ratings',
'comments'
];
public function users()
{
return $this->belongsToMany(User::class, 'user_book');
}
public function author()
{
return $this->belongsTo(Author::class);
}
public function allReadingSessions()
{
return $this->hasMany(ReadingSession::class);
}
public function readingSessions()
{
return $this->hasMany(ReadingSession::class)
->where('user_id', Auth::user()->id);
}
public function ratings()
{
return $this->hasMany(Rating::class);
}
public function userRating()
{
return $this->hasMany(Rating::class)
->where('user_id', Auth::user()->id);
}
public function comments()
{
return $this->morphMany('App\Models\Comment', 'commentable');
}
ReadingSession.php
protected $with = ['comments'];
public function user()
{
return $this->belongsTo(User::class);
}
public function book()
{
return $this->belongsTo(Book::class);
}
public function comments()
{
return $this->morphMany('App\Models\Comment', 'commentable');
}
Comment.php
public function commentable()
{
return $this->morphTo();
}
ये अनंत लूप बनाने के लिए लगता है । क्या कोई मुझे गलत काम कर रहा है पर संकेत दे सकता है?