forked from admin/services_core
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Nas;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class NasResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
$data = $this->resource->attributesToArray();
|
|
unset($data['api_password'], $data['radius_secret'], $data['community'], $data['auth_password'], $data['privacy_password'], $data['password']);
|
|
|
|
$data['tenant'] = $this->whenLoaded('tenant', fn () => [
|
|
'id' => $this->tenant->id,
|
|
'tenant_code' => $this->tenant->tenant_code,
|
|
'tenant_name' => $this->tenant->tenant_name,
|
|
]);
|
|
|
|
foreach ([
|
|
'api_password' => 'has_api_password',
|
|
'radius_secret' => 'has_radius_secret',
|
|
'community' => 'has_community',
|
|
'auth_password' => 'has_auth_password',
|
|
'privacy_password' => 'has_privacy_password',
|
|
'password' => 'has_password',
|
|
] as $column => $flag) {
|
|
if (array_key_exists($column, $this->resource->getAttributes())) {
|
|
$data[$flag] = filled($this->resource->getRawOriginal($column));
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|