I have an issue with transform and availableIncludes.
This is my LeagueTransformer.php
<?php
...
/**
* List of resources possible to include
*
* @var array
*/
protected $availableIncludes = [
'teams'
];
public function transform(League $league)
{
return [
'id' => (int) $league->id,
'name' => (string) $league->name,
'slug_name' => (string) $league->slug_name,
'nice_name' => (string) $league->nice_name,
'image_logo' => (string) $league->image_logo_league,
'active_year' => (string) $league->year,
'country_code' => (string) $league->country_code
];
}
/**
* Include Teams
*
* @return League\Fractal\ItemResource
*/
public function includeTeams(League $league)
{
// here i have my problem
$teams = $league->teams();
return $this->collection($teams, new TeamsTransformer(), 'teams');
}
When i do, $leagues->teams()->count() i got, 30 rows, but this never passed out to response. And yes, i put on my query string ?include=teams, but nothing. This is the result,
you need to call $teams = $league->teams; (without the ()). You want to pass a collection to the $this->collection() method and not a Builder instance!
Hello,
I have an issue with transform and availableIncludes.
This is my LeagueTransformer.php
When i do, $leagues->teams()->count() i got, 30 rows, but this never passed out to response. And yes, i put on my query string ?include=teams, but nothing. This is the result,