Adding device's field in get_alert_rule and list-alert-rules API function (new) (#14481)

* Adding device's field in get_alert_rule and lis-alert-rules API function

* Converting SQL request for list/get_alert_rules to Eloquent (thanks a lot to Murrant)

* Manually added #14500 to pass pipeline

* Fixing StyleCI error + trying to fix PHPStan errors

* Trying to fix PHPStan errors (part 2)
This commit is contained in:
geg347
2022-11-09 15:21:41 +01:00
committed by GitHub
parent b9d8a7c33c
commit 96c7e7166e
2 changed files with 34 additions and 8 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\Device $devices
* @property \App\Models\DeviceGroup $groups
* @property \App\Models\Location $locations
*/
class AlertRule extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$rule = parent::toArray($request);
$rule['devices'] = $this->devices->pluck('device_id')->all();
$rule['groups'] = $this->groups->pluck('id')->all();
$rule['locations'] = $this->locations->pluck('id')->all();
return $rule;
}
}