mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
API: upload sections list
This commit is contained in:
44
app/Http/Resources/SearchBoxResource.php
Normal file
44
app/Http/Resources/SearchBoxResource.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\SearchBox;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SearchBoxResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
/** @var SearchBox $resource */
|
||||
$searchBox = $this->resource;
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'name' => $this->displaySectionName,
|
||||
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
|
||||
];
|
||||
$subCategories = [];
|
||||
$lang = get_langfolder_cookie();
|
||||
$fields = array_keys(SearchBox::$taxonomies);
|
||||
if (!empty($searchBox->extra['taxonomy_labels'])) {
|
||||
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
$relationName = "taxonomy_$field";
|
||||
if ($searchBox->relationLoaded($relationName)) {
|
||||
$subCategories[] = [
|
||||
'field' => $field,
|
||||
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
|
||||
'data' => MediaResource::collection($searchBox->{$relationName}),
|
||||
];
|
||||
}
|
||||
}
|
||||
$out['sub_categories'] = $this->when($this->showsubcat, $subCategories);
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user