public function index()
{
$mods = Mod::with('categories')
->with('mod_author')
->with('files')
->paginate('10');
return ModResource::collection($mods);
}
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'author' => new AuthorResource($this->mod_author),
'sticky' => $this->sticky,
'categories' => CategoryResource::collection($this->categories),
'files' => [
'archives' => File::where('type', 'mod')->where('mod_id', $this->id)->get(),
]
];
}
public function index()
{
$mods = Mod::with('categories')
->with('mod_author')
->with(['files' => function($query){
return $query->where('type', 'mod');
}])
->paginate('10');
return ModResource::collection($mods);
}
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'author' => new AuthorResource($this->mod_author),
'sticky' => $this->sticky,
'categories' => CategoryResource::collection($this->categories),
'files' => $this->whenLoaded('files', [
'archives' => $this->files,
])
];
}
public function files() {
return $this->hasMany(File::class);
}
public function mod_files() {
return $this->files()->where('type', 'mod');
}
public function index()
{
$mods = Mod::with('categories')
->with('mod_author')
->with('files')
->with('mod_files')
->paginate('10');
return ModResource::collection($mods);
}