mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
26 lines
621 B
PHP
26 lines
621 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
abstract class BaseResource extends JsonResource
|
|
{
|
|
protected abstract function getResourceName(): string;
|
|
|
|
protected function whenIncludeField($field): bool
|
|
{
|
|
return $this->whenInclude($field, "include_fields");
|
|
}
|
|
|
|
private function whenInclude($field, $prefix): bool
|
|
{
|
|
$fields = request()->input("$prefix." . $this->getResourceName());
|
|
if (!$fields) {
|
|
return false;
|
|
}
|
|
$fieldsArr = explode(',', $fields);
|
|
return in_array($field, $fieldsArr);
|
|
}
|
|
}
|