add alersts api
This commit is contained in:
27
app/Models/Alert.php
Normal file
27
app/Models/Alert.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Alert extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Casts
|
||||
*/
|
||||
protected $casts = [
|
||||
'seen_at' => 'datetime'
|
||||
];
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -196,5 +196,14 @@ class LoanOrder extends Model
|
||||
|
||||
static::creating(LoanOrderRepo::creating());
|
||||
static::created(LoanOrderRepo::created());
|
||||
static::updated(function (LoanOrder $model) {
|
||||
info($model->notes);
|
||||
if ($model->notes && $model->wasChanged('notes')) {
|
||||
auth()->user()->alerts()->create([
|
||||
'name' => 'Duýdyryş',
|
||||
'value' => $model->notes,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,14 @@ class User extends Authenticatable
|
||||
return $this->hasMany(CardOrder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alerts
|
||||
*/
|
||||
public function alerts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Alert::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user has role.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user