Skip to main content

officelifehq/officelife

943 stars
2 code files
View officelifehq/officelife on GitHub

app/Jobs/LogAccountAudit.php

Open in GitHub
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use App\Services\Logs\LogAccountAction;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
 
class LogAccountAudit implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
public array $auditLog;
 
public function __construct(array $auditLog)
{
$this->auditLog = $auditLog;
}
 
public function handle(): void
{
(new LogAccountAction)->execute([
'company_id' => $this->auditLog['company_id'],
'author_id' => $this->auditLog['author_id'],
'author_name' => $this->auditLog['author_name'],
'audited_at' => $this->auditLog['audited_at'],
'action' => $this->auditLog['action'],
'objects' => $this->auditLog['objects'],
]);
}
}

app/Services/Company/Adminland/Company/JoinCompany.php

Open in GitHub
use App\Jobs\LogAccountAudit;
use App\Services\BaseService;
use App\Models\Company\Company;
 
class JoinCompany extends BaseService
{
//
public function execute(array $data): Company
{
$this->data = $data;
$this->validate();
$this->findCompany();
$this->addUser();
$this->logAccountAudit();
 
return $this->company;
}
//
private function logAccountAudit(): void
{
LogAccountAudit::dispatch([
'company_id' => $this->company->id,
'action' => 'employee_joined_company',
'author_id' => $this->employee->id,
'author_name' => $this->employee->name,
'audited_at' => Carbon::now(),
'objects' => json_encode([
'company_name' => $this->company->name,
]),
])->onQueue('low');
}
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.