Have you tried getting the model data with the relationship?
class PersonController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
return PersonResource::collection(Person::orderBy('lastName')->with('participations')->get());
}
The in the Resource you could just get whatever Attribute you want from participations:
class PersonResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
"id"=> $this->id,
'firstName'=>$this->firstName,
'lastName'=>$this->lastName,
'fullName'=>$this->participations->fullname // Whatever field you need from "participations"
'email'=>$this->email,
'phone'=>$this->phone,
'memberSince'=>$this->memberSince,
'memberLastYear'=>$this->memberLastYear
];
}
}