Answer the question
In order to leave comments, you need to log in
How to get related data through an intermediary?
I need to get all users with their requests and comments (see screenshot). How to register the connection in this case?
Comment Model
class Comment extends Model
{
use HasFactory;
public function subcategory(){
return $this->hasMany(Comment::class, 'parent_id');
}
}
class Ticket extends Model
{
use HasFactory;
public function user()
{
return $this->belongsTo(User::class);
}
public function department()
{
return $this->belongsTo(Department::class);
}
}
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
public function ticket()
{
return $this->hasMany(Ticket::class);
}
}
Answer the question
In order to leave comments, you need to log in
If you get all user comments - add user_id to comments and hasMany to User.
If tickets with User::with('tickets.comments') and hasmany comments in ticket
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question