Files
numstation-web/app/Models/UserNotification.php

73 lines
1.9 KiB
PHP
Raw Normal View History

2023-12-22 12:35:55 +08:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserNotification extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'title',
'description',
'category',
'target_id',
'target_type',
'is_read',
'is_admin',
'status',
];
public function getUrlAttribute()
{
$url = '';
if (strtolower($this->category) == 'service chat') {
$url = route('cms.chat');
$chat = ServiceChat::find($this->target_id);
if ($chat) {
$url = $url . '?user_id=' . $chat->user_id . '&company_id=' . $chat->company_id . '&chat_id=' . $this->target_id;
}
}
else if (strtolower($this->category) == 'bookkeeping queue') {
$url = route('cms.bookkeepings');
}
return $url;
}
public function getCategoryUrlAttribute()
{
$url = '';
if (strtolower($this->category) == 'service chat') {
$url = route('cms.chat');
}
else if (strtolower($this->category) == 'bookkeeping queue') {
$url = route('cms.bookkeepings');
}
return $url;
}
public function getImageUrlAttribute()
{
$url = '';
if (strtolower($this->category) == 'service chat') {
$url = asset('themes/tailwind/images/building.svg');
}
else if (strtolower($this->category) == 'bookkeeping queue') {
$ext = pathinfo($this->description, PATHINFO_EXTENSION);
$url = $ext == 'pdf' ? asset('themes/tailwind/images/pdf.svg') : asset('themes/tailwind/images/jpg.svg');
}
return $url;
}
}