adrema/app/Lib/HasMeta.php

45 lines
963 B
PHP
Raw Normal View History

2023-02-23 22:43:13 +01:00
<?php
namespace App\Lib;
/** @mixin \Illuminate\Http\Resources\Json\JsonResource */
trait HasMeta
{
/**
* Create a new anonymous resource collection.
*
* @param mixed $resource
*
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/
public static function collection($resource)
{
$meta = self::meta();
if (!count($meta)) {
return parent::collection($resource);
}
return parent::collection($resource)->additional([
'meta' => $meta,
]);
}
2023-03-07 09:37:49 +01:00
/**
* Create a new anonymous resource collection without meta.
*
* @param mixed $resource
*
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/
2023-03-07 01:35:39 +01:00
public static function collectionWithoutMeta($resource)
{
return parent::collection($resource);
}
2023-02-23 22:43:13 +01:00
public static function meta(): array
{
return [];
}
}