mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
extract broadcasting properties
This commit is contained in:
parent
d12e277230
commit
48a6053100
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Utils\Traits\Invoice\Broadcasting;
|
||||||
|
|
||||||
|
use App\Transformers\ArraySerializer;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use League\Fractal\Manager;
|
||||||
|
use League\Fractal\Resource\Item;
|
||||||
|
|
||||||
|
trait DefaultInvoiceBroadcast
|
||||||
|
{
|
||||||
|
public function broadcastOn(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new PrivateChannel("company-{$this->company->company_key}"),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function broadcastWith(): array
|
||||||
|
{
|
||||||
|
$manager = new Manager();
|
||||||
|
$manager->setSerializer(new ArraySerializer());
|
||||||
|
$class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->invoice));
|
||||||
|
|
||||||
|
$transformer = new $class();
|
||||||
|
|
||||||
|
$resource = new Item($this->invoice, $transformer, $this->invoice->getEntityType());
|
||||||
|
$data = $manager->createData($resource)->toArray();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user