feat(admin): star/tags marks, service product-type filter, campaign bulk actions, SMTP test
- Star (is_starred) and colored tags for services, customers, orders, invoices:
Markable trait, tags/taggables tables, PATCH administrator/marks/{type}/{key},
tag CRUD, list filters starred / tag_ids[]
- GET administrator/services accepts product_type (falls back to product type
for legacy rows without services.type)
- Mail campaigns: bulk cancel / retry failed / delete; cancelled campaigns are
skipped by SendMailCampaignRecipient
- POST administrator/settings/test-smtp sends a test email through the saved
mail transport
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
46aa138eec
commit
40bf6b54f9
@@ -53,7 +53,7 @@ class CustomerController extends Controller
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 500);
|
||||
$paginator = $this->customerRepository
|
||||
->filter($request->all(), [], ['hosting', 'vps', 'domain'], ['*'], true)
|
||||
->filter($request->all(), ['tags'], ['hosting', 'vps', 'domain'], ['*'], true)
|
||||
->paginate($perPage);
|
||||
|
||||
return $this->paginatedResponse($paginator);
|
||||
|
||||
@@ -49,6 +49,7 @@ class InvoiceController extends Controller
|
||||
'customer',
|
||||
'order',
|
||||
...OrderItemServiceResource::relationsFor('order.orderItems'),
|
||||
'tags',
|
||||
],
|
||||
[],
|
||||
['*'],
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\MailCampaign\Concerns;
|
||||
|
||||
use App\Jobs\Mail\SendMailCampaignRecipient;
|
||||
use App\Models\Mail;
|
||||
use App\Models\MailCampaign;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
trait HandlesCampaignBulkActions
|
||||
{
|
||||
public function bulkAction(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'action' => 'required|in:cancel,retry-failed',
|
||||
'uuids' => 'required|array|min:1|max:200',
|
||||
'uuids.*' => 'string',
|
||||
]);
|
||||
|
||||
$campaigns = MailCampaign::whereIn('uuid', $data['uuids'])->get();
|
||||
|
||||
$message = $data['action'] === 'cancel'
|
||||
? $this->cancelCampaigns($campaigns)
|
||||
: $this->retryFailedRecipients($campaigns);
|
||||
|
||||
return response()->json(['error' => false, 'message' => $message]);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'uuids' => 'required|array|min:1|max:200',
|
||||
'uuids.*' => 'string',
|
||||
]);
|
||||
|
||||
$deleted = MailCampaign::whereIn('uuid', $data['uuids'])
|
||||
->whereIn('status', MailCampaign::FINISHED_STATUSES)
|
||||
->delete();
|
||||
$skipped = count($data['uuids']) - $deleted;
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => "Đã xoá {$deleted} chiến dịch."
|
||||
. ($skipped > 0 ? " Bỏ qua {$skipped} chiến dịch đang gửi (huỷ gửi trước khi xoá)." : ''),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, MailCampaign> $campaigns
|
||||
*/
|
||||
private function cancelCampaigns(Collection $campaigns): string
|
||||
{
|
||||
$cancelled = MailCampaign::whereKey($campaigns->modelKeys())
|
||||
->whereIn('status', MailCampaign::ACTIVE_STATUSES)
|
||||
->update(['status' => MailCampaign::STATUS_CANCELLED, 'completed_at' => now()]);
|
||||
|
||||
return "Đã huỷ gửi {$cancelled} chiến dịch. Email đã gửi trước đó không bị thu hồi.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, MailCampaign> $campaigns
|
||||
*/
|
||||
private function retryFailedRecipients(Collection $campaigns): string
|
||||
{
|
||||
$retried = 0;
|
||||
|
||||
foreach ($campaigns->whereIn('status', ['completed', 'failed']) as $campaign) {
|
||||
DB::transaction(function () use ($campaign, &$retried) {
|
||||
$failedLogs = Mail::where('campaign_id', $campaign->id)
|
||||
->where('status', array_search('failed', Mail::STATUS_MAP, true))
|
||||
->lockForUpdate()
|
||||
->get(['id', 'to', 'customer_id']);
|
||||
if ($failedLogs->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Mail::whereKey($failedLogs->modelKeys())->delete();
|
||||
$campaign->forceFill([
|
||||
'failed_count' => max(0, $campaign->failed_count - $failedLogs->count()),
|
||||
'status' => 'sending',
|
||||
'completed_at' => null,
|
||||
])->save();
|
||||
|
||||
foreach ($failedLogs as $log) {
|
||||
SendMailCampaignRecipient::dispatch($campaign->id, $log->customer_id, $log->to)->afterCommit();
|
||||
}
|
||||
$retried += $failedLogs->count();
|
||||
});
|
||||
}
|
||||
|
||||
return $retried > 0
|
||||
? "Đã đưa {$retried} email lỗi vào hàng đợi gửi lại."
|
||||
: 'Không có email lỗi nào để gửi lại (chỉ gửi lại chiến dịch đã kết thúc).';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\MailCampaign;
|
||||
|
||||
use App\Http\Controllers\Api\Admin\MailCampaign\Concerns\HandlesCampaignBulkActions;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\Mail\SendMailCampaignRecipient;
|
||||
use App\Models\Customer;
|
||||
@@ -19,6 +20,8 @@ use Illuminate\Validation\ValidationException;
|
||||
|
||||
final class MailCampaignController extends Controller
|
||||
{
|
||||
use HandlesCampaignBulkActions;
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$limit = min((int) $request->get('per_page', 20), 200);
|
||||
|
||||
@@ -38,6 +38,7 @@ class OrderController extends Controller
|
||||
'invoice',
|
||||
'orderItems.os',
|
||||
...OrderItemServiceResource::relationsFor('orderItems'),
|
||||
'tags',
|
||||
],
|
||||
[],
|
||||
['*'],
|
||||
|
||||
@@ -27,10 +27,14 @@ class ServiceController extends Controller
|
||||
{
|
||||
$perPage = min((int) ($request->per_page ?? 15), 100);
|
||||
|
||||
$query = Service::with(['customer:id,uuid,fullname,email', 'product:id,uuid,name', 'invoice:id,invoice_number', 'vmware:id,name,module_ip_address', 'orderItem:id,order_id', 'orderItem.order:id,order_num'])
|
||||
$query = Service::with(['customer:id,uuid,fullname,email', 'product:id,uuid,name,product_type', 'invoice:id,invoice_number', 'vmware:id,name,module_ip_address', 'orderItem:id,order_id', 'orderItem.order:id,order_num', 'tags'])
|
||||
->marked($request->all())
|
||||
->where(fn($q) => $q->whereNull('order_item_id')->orWhereNull('type')->orWhere('type', '!=', 'domain'))
|
||||
->when($request->filter, fn($q, $v) => $q->where('server_name', 'like', "%{$v}%"))
|
||||
->when($request->status, fn($q, $v) => $q->where('status', $v))
|
||||
->when($request->product_type, fn($q, $v) => $q->where(fn($typed) => $typed
|
||||
->where('type', $v)
|
||||
->orWhere(fn($legacy) => $legacy->whereNull('type')->whereHas('product', fn($product) => $product->where('product_type', $v)))))
|
||||
->when($request->customer_id, fn($q, $v) => $q->where('customer_id', $v))
|
||||
->when($request->boolean('unassigned'), fn($q) => $q->whereNull('customer_id'));
|
||||
|
||||
|
||||
@@ -9,11 +9,13 @@ use App\Http\Facade\SignRSA;
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Models\Setting;
|
||||
use App\Support\PublicSetting;
|
||||
use App\Support\AutoEmailGate;
|
||||
use App\Support\MailSettings;
|
||||
use App\Support\Turnstile;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
@@ -189,6 +191,42 @@ class SettingController extends Controller
|
||||
return response()->json(['error' => false, 'message' => 'Đã gửi tin nhắn test thành công.']);
|
||||
}
|
||||
|
||||
public function testSmtp(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['email' => 'required|email|max:255']);
|
||||
|
||||
if (!AutoEmailGate::mailEnabled()) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Hệ thống đang tắt gửi email (Mẫu email → Cài đặt). Bật lại rồi gửi test.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
MailSettings::refresh(app('mail.manager'));
|
||||
$mailer = MailSettings::transport() ?? config('mail.default');
|
||||
|
||||
try {
|
||||
Mail::mailer($mailer)->html(
|
||||
'<p>Đây là email test từ Portal Admin.</p>'
|
||||
. '<p>Nếu bạn nhận được email này, cấu hình gửi email (' . e($mailer) . ') đang hoạt động.</p>'
|
||||
. '<p>Gửi lúc ' . now()->format('H:i:s d/m/Y') . '.</p>',
|
||||
fn ($message) => $message->to($data['email'])->subject('[Portal] Email test cấu hình SMTP'),
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Gửi email test thất bại: ' . $e->getMessage(),
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => $mailer === 'log'
|
||||
? 'Driver đang là Log: email được ghi vào log, không gửi thật.'
|
||||
: "Đã gửi email test tới {$data['email']}.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function uploadMedia(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Tag;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Markables;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MarkController extends Controller
|
||||
{
|
||||
public function update(Request $request, string $key): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'is_starred' => 'sometimes|boolean',
|
||||
'tag_ids' => 'sometimes|array',
|
||||
'tag_ids.*' => 'integer|distinct|exists:tags,id',
|
||||
]);
|
||||
|
||||
$model = Markables::find($request->route('type'), $key);
|
||||
|
||||
DB::transaction(function () use ($model, $data) {
|
||||
if (array_key_exists('is_starred', $data)) {
|
||||
$model->timestamps = false;
|
||||
$model->forceFill(['is_starred' => $data['is_starred']])->save();
|
||||
}
|
||||
if (array_key_exists('tag_ids', $data)) {
|
||||
$model->tags()->sync($data['tag_ids']);
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'is_starred' => (bool) $model->is_starred,
|
||||
'tags' => $model->tags()->get(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Tag;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TagController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => Tag::withCount(['services', 'customers', 'orders', 'invoices'])->orderBy('title')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã tạo tag.',
|
||||
'data' => Tag::create($this->validated($request)),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$tag = Tag::findOrFail($id);
|
||||
$tag->update($this->validated($request, $tag->id));
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Đã cập nhật tag.', 'data' => $tag]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
Tag::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Đã xoá tag.']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{title: string, color: string}
|
||||
*/
|
||||
private function validated(Request $request, ?int $ignoreId = null): array
|
||||
{
|
||||
return $request->validate([
|
||||
'title' => ['required', 'string', 'max:50', Rule::unique('tags', 'title')->ignore($ignoreId)],
|
||||
'color' => ['required', 'string', 'regex:' . Tag::COLOR_PATTERN],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ class CustomerResource extends JsonResource
|
||||
'email_marketing' => (bool) $this->email_marketing,
|
||||
'receive_deposit' => (bool) $this->receive_deposit,
|
||||
'created_at' => $this->created_at,
|
||||
'is_starred' => (bool) $this->is_starred,
|
||||
'tags' => $this->whenLoaded('tags'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class InvoiceResource extends JsonResource
|
||||
'amount_paid' => (int) $this->amount_paid,
|
||||
'outstanding' => \App\Services\InvoicePaymentService::outstanding($this->resource),
|
||||
'status' => $this->status,
|
||||
'is_starred' => (bool) $this->is_starred,
|
||||
'tags' => $this->whenLoaded('tags'),
|
||||
'due_date' => $this->due_date,
|
||||
'paid_at' => $this->paid_at,
|
||||
'reminder_step' => (int) $this->reminder_step,
|
||||
|
||||
@@ -103,6 +103,8 @@ class OrderResource extends JsonResource
|
||||
'note' => $this->note,
|
||||
'client_ip' => $this->client_ip,
|
||||
'status' => $this->status,
|
||||
'is_starred' => (bool) $this->is_starred,
|
||||
'tags' => $this->whenLoaded('tags'),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'vmwares' => $this->whenLoaded('moduleVmwares', fn() => $this->moduleVmwares->map(fn($vm) => [
|
||||
|
||||
@@ -32,7 +32,7 @@ class SendMailCampaignRecipient implements ShouldQueue
|
||||
public function handle(MailCampaignRenderer $renderer): void
|
||||
{
|
||||
$campaign = MailCampaign::with('template')->find($this->campaignId);
|
||||
if (!$campaign) {
|
||||
if (!$campaign || $campaign->status === MailCampaign::STATUS_CANCELLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class SendMailCampaignRecipient implements ShouldQueue
|
||||
$campaign->increment($failed ? 'failed_count' : 'sent_count');
|
||||
|
||||
$finished = MailCampaign::whereKey($campaign->id)
|
||||
->whereIn('status', ['queued', 'sending'])
|
||||
->whereIn('status', MailCampaign::ACTIVE_STATUSES)
|
||||
->whereRaw('sent_count + failed_count >= total_recipients')
|
||||
->update([
|
||||
'status' => DB::raw("CASE WHEN sent_count = 0 THEN 'failed' ELSE 'completed' END"),
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
|
||||
trait Markable
|
||||
{
|
||||
public function initializeMarkable(): void
|
||||
{
|
||||
$this->mergeCasts(['is_starred' => 'boolean']);
|
||||
}
|
||||
|
||||
public function tags(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable')->orderBy('tags.title');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $filters
|
||||
*/
|
||||
public function scopeMarked(Builder $query, array $filters): Builder
|
||||
{
|
||||
$tagIds = array_values(array_filter(array_map('intval', (array) ($filters['tag_ids'] ?? []))));
|
||||
|
||||
return $query
|
||||
->when(
|
||||
filter_var($filters['starred'] ?? false, FILTER_VALIDATE_BOOL),
|
||||
fn (Builder $q) => $q->where($this->qualifyColumn('is_starred'), true),
|
||||
)
|
||||
->when($tagIds, fn (Builder $q) => $q->whereHas('tags', fn (Builder $tags) => $tags->whereIn('tags.id', $tagIds)));
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\Cache\CacheServiceInterface;
|
||||
use App\Models\Concerns\Markable;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -13,7 +14,7 @@ use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class Customer extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use HasFactory, HasUuids, SoftDeletes, LogsActivity;
|
||||
use HasFactory, HasUuids, SoftDeletes, LogsActivity, Markable;
|
||||
|
||||
protected $table = 'customers';
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Models\Concerns\Markable;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -11,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, LogsActivity;
|
||||
use HasFactory, SoftDeletes, LogsActivity, Markable;
|
||||
|
||||
protected $table = 'invoices';
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@ class MailCampaign extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const STATUS_CANCELLED = 'cancelled';
|
||||
|
||||
public const ACTIVE_STATUSES = ['queued', 'sending'];
|
||||
|
||||
public const FINISHED_STATUSES = ['completed', 'failed', self::STATUS_CANCELLED];
|
||||
|
||||
protected $table = 'mail_campaigns';
|
||||
|
||||
protected $fillable = [
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\Markable;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -10,7 +11,7 @@ use App\Models\ModuleVmware;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, LogsActivity;
|
||||
use HasFactory, SoftDeletes, LogsActivity, Markable;
|
||||
|
||||
protected $table = 'orders';
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\Markable;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -10,7 +11,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Service extends Model
|
||||
{
|
||||
use HasFactory, HasUuids, SoftDeletes, LogsActivity;
|
||||
use HasFactory, HasUuids, SoftDeletes, LogsActivity, Markable;
|
||||
|
||||
public function uniqueIds(): array
|
||||
{
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
public const COLOR_PATTERN = '/^#[0-9a-fA-F]{6}$/';
|
||||
|
||||
protected $fillable = ['title', 'color'];
|
||||
|
||||
protected $hidden = ['pivot'];
|
||||
|
||||
public function services(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Service::class, 'taggable');
|
||||
}
|
||||
|
||||
public function customers(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Customer::class, 'taggable');
|
||||
}
|
||||
|
||||
public function orders(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Order::class, 'taggable');
|
||||
}
|
||||
|
||||
public function invoices(): MorphToMany
|
||||
{
|
||||
return $this->morphedByMany(Invoice::class, 'taggable');
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class CustomerRepository extends BaseRepository implements CustomerRepositoryInt
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
$model = $this->model->with($relationships)->select($select)->marked($data);
|
||||
if (isset($data['filter']) && ! empty($data['filter'])) {
|
||||
$model = $model->where(function ($query) use ($data) {
|
||||
$filter = trim($data['filter']);
|
||||
|
||||
@@ -17,7 +17,7 @@ class InvoiceRepository extends BaseRepository implements InvoiceRepositoryInter
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
$model = $this->model->with($relationships)->select($select)->marked($data);
|
||||
|
||||
if (isset($data['client']) && ! empty($data['client'])) {
|
||||
$model = $model->where("customer_id", $data['client']);
|
||||
|
||||
@@ -17,7 +17,7 @@ class OrderRepository extends BaseRepository implements OrderRepositoryInterface
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
$model = $this->model->with($relationships)->select($select)->marked($data);
|
||||
if (isset($data['client']) && ! empty($data['client'])) {
|
||||
$model = $model->where("customer_id", $data['client']);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ final class MailSettings
|
||||
Config::set('mail', $config);
|
||||
}
|
||||
|
||||
public static function transport(): ?string
|
||||
{
|
||||
return self::resolve()['transport'] ?? null;
|
||||
}
|
||||
|
||||
public static function refresh(object $mailer): void
|
||||
{
|
||||
self::apply();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Order;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
final class Markables
|
||||
{
|
||||
/**
|
||||
* @var array<string, array{model: class-string<Model>, key: string, permission: string}>
|
||||
*/
|
||||
public const TYPES = [
|
||||
'services' => ['model' => Service::class, 'key' => 'id', 'permission' => 'customer.edit'],
|
||||
'customers' => ['model' => Customer::class, 'key' => 'uuid', 'permission' => 'customer.edit'],
|
||||
'orders' => ['model' => Order::class, 'key' => 'id', 'permission' => 'order.edit'],
|
||||
'invoices' => ['model' => Invoice::class, 'key' => 'id', 'permission' => 'invoice.edit'],
|
||||
];
|
||||
|
||||
public static function find(string $type, string $key): Model
|
||||
{
|
||||
$definition = self::TYPES[$type];
|
||||
|
||||
return $definition['model']::query()->where($definition['key'], $key)->firstOrFail();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user