2 Answers
I Found The Solution!
First I was supposed to add a pivot in the Models
Event Model:
public function announcements() {
return $this->belongsToMany(User::class, 'announcements')->withPivot('message');
}
User Model:
public function announcements() {
return $this->belongsToMany(Event::class, 'announcements')->withPivot('message');
}
And Finally Loop Through The Results To Get Messages.
EventsController:
$ann = [];
foreach ($event->announcements as $a) {
$ann[] = [
"name" => $a->name,
"announcement" => $a->pivot->message,
"created_at" => $a->pivot->created_at,
];
}
It Worked Fine!
0 comments:
Post a Comment
Thanks