user notifications added

This commit is contained in:
2025-05-09 22:02:31 +05:00
parent a80c563773
commit a789a5cefa
4 changed files with 69 additions and 4 deletions

View File

@@ -3,9 +3,13 @@
namespace App\Repos\Order\Loan;
use App\Models\Branch\Branch;
use App\Nova\Resources\Order\Loan\LoanOrder as NovaLoanOrder;
use App\Repos\Order\OrderRepo;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Notifications\NovaNotification;
use Laravel\Nova\URL;
class LoanOrderRepo
{
@@ -40,14 +44,14 @@ class LoanOrderRepo
public static function created(): Closure
{
return function ($model) {
$model->update(['unique_id' => static::fillUniqueId($model)]);
$model->update(['unique_id' => static::generateUniqueId($model)]);
};
}
/**
* Fill unique id
*/
public static function fillUniqueId(mixed $model): string
public static function generateUniqueId(mixed $model): string
{
return sprintf(
'TB%s-%s',
@@ -55,4 +59,23 @@ class LoanOrderRepo
$model->id,
);
}
public static function notifyUser(NovaRequest $request, Model $model, string $message, string $type = 'info'): void
{
/** @var \App\Models\Order\Loan\LoanOrder */
$loanOrder = $model;
$id = $loanOrder->id;
$nova_path = config('nova.path');
$loan_order_path = NovaLoanOrder::uriKey();
$url = url($nova_path.'/resources/'.$loan_order_path.'/'.$id);
$request->user()->notifyNow(
NovaNotification::make()
->message($message.': '.$loanOrder->unique_id)
->action(__('See'), URL::remote($url))
->icon('cash')
->type($type)
);
}
}