add projet

This commit is contained in:
root
2026-03-05 12:29:37 -05:00
parent 8d1eef8ba8
commit 23b7db1107
9109 changed files with 1106501 additions and 73 deletions
+87
View File
@@ -0,0 +1,87 @@
<?php
namespace App\Models;
use App\Models\BaseModel;
class WhatsappInviteLog extends BaseModel
{
protected $table = 'whatsapp_invites_log';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $fillable = [
'parent_id',
'email',
'class_section_id',
'link_id',
'status',
'error_message',
'sent_at',
];
public $timestamps = false; // we handle sent_at manually
const CREATED_AT = '';
const UPDATED_AT = '';
// Validation (optional)
protected $validationRules = [
'parent_id' => 'required|integer',
'email' => 'required|valid_email|max_length[255]',
'status' => 'required|max_length[20]',
'class_section_id' => 'permit_empty|integer',
'link_id' => 'permit_empty|integer',
];
protected $validationMessages = [];
protected $skipValidation = false;
/**
* Log a successful send.
*/
public function logSuccess(int $parentId, string $email, int $classSectionId = null, int $linkId = null): bool
{
return (bool) $this->insert([
'parent_id' => $parentId,
'email' => $email,
'class_section_id' => $classSectionId,
'link_id' => $linkId,
'status' => 'sent',
'error_message' => null,
'sent_at' => utc_now(),
]);
}
/**
* Log a failure with error message.
*/
public function logFailure(int $parentId, string $email, string $error, int $classSectionId = null, int $linkId = null): bool
{
return (bool) $this->insert([
'parent_id' => $parentId,
'email' => $email,
'class_section_id' => $classSectionId,
'link_id' => $linkId,
'status' => 'failed',
'error_message' => $error,
'sent_at' => utc_now(),
]);
}
/**
* Get logs for a specific term, parent, or section (optional helper).
*/
public function getLogs(?int $parentId = null, ?int $classSectionId = null): array
{
$builder = $this->builder();
if ($parentId) {
$builder->where('parent_id', $parentId);
}
if ($classSectionId) {
$builder->where('class_section_id', $classSectionId);
}
return $builder->orderBy('sent_at', 'DESC')->get()->getResultArray();
}
}