send notification

This commit is contained in:
2025-05-12 13:30:09 +05:00
parent 8aca14f17e
commit f0a08a8042
4 changed files with 84 additions and 16 deletions

View File

@@ -3,10 +3,13 @@
namespace App\Repos\Order\Loan;
use App\Models\Branch\Branch;
use App\Models\Order\Loan\LoanOrder;
use App\Nova\Resources\Order\Loan\LoanOrder as NovaLoanOrder;
use App\Repos\Order\OrderRepo;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Notifications\NovaNotification;
use Laravel\Nova\URL;
@@ -62,14 +65,11 @@ class LoanOrderRepo
public static function notifyUser(
NovaRequest $request,
Model $model,
LoanOrder $loanOrder,
string $message,
string $type = 'info',
string $icon = 'eye',
): void {
/** @var \App\Models\Order\Loan\LoanOrder */
$loanOrder = $model;
$id = $loanOrder->id;
$nova_path = config('nova.path');
$loan_order_path = NovaLoanOrder::uriKey();
@@ -83,4 +83,49 @@ class LoanOrderRepo
->type($type)
);
}
public static function notifyOperators(
LoanOrder $loanOrder,
string $message,
string $type = 'info',
string $icon = 'eye',
): void {
$id = $loanOrder->id;
$nova_path = config('nova.path');
$loan_order_path = NovaLoanOrder::uriKey();
$url = url($nova_path.'/resources/'.$loan_order_path.'/'.$id);
// Get users related with branch...
$branch_users = DB::table('branch_user')->where('branch_id', $loanOrder->branch_id)->pluck('user_id');
// Check if they have permission for viewing loan order
$loanOrderOperators = DB::table('model_has_permissions')
->where('permission_id', view_loan_order_permission_id())
->whereIntegerInRaw('model_id', $branch_users)
->pluck('model_id');
$loanOrderOperators->each(function ($branch_user) use ($icon, $message, $url, $type) {
DB::table('nova_notifications')->insert([
'id' => Str::uuid(),
'type' => 'Laravel\Nova\Notifications\NovaNotification',
'notifiable_type' => 'App\Models\User',
'notifiable_id' => $branch_user,
'data' => json_encode([
'component' => 'message-notification',
'icon' => $icon,
'message' => $message,
'actionText' => 'Görmek',
'actionUrl' => [
'url' => URL::remote($url),
'remote' => true,
],
'openInNewTab' => false,
'type' => $type,
'iconClass' => 'text-sky-500',
]),
'created_at' => now(),
'updated_at' => now(),
]);
});
}
}