12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class InternalMessage extends Model
- {
- protected $table = 'internal_message';
- public function getRouteKeyName()
- {
- return 'uid';
- }
- public function messageVideoFile()
- {
- return $this->hasOne(SystemFile::class, 'id', 'message_video_file_id');
- }
- public function fromPro()
- {
- return $this->hasOne(Pro::class, 'id', 'from_pro_id');
- }
- public function toPro()
- {
- return $this->hasOne(Pro::class, 'id', 'to_pro_id');
- }
- public function regardingClient()
- {
- return $this->hasOne(Client::class, 'id', 'regarding_client_id');
- }
- public function attachments()
- {
- return $this->hasMany(InternalMessageAttachment::class, 'internal_message_id', 'id');
- }
- public function readBy() {
- $readBy = '-';
- if($this->read_by_id) {
- $session = AppSession::where('id', $this->read_by_id)->first();
- switch($session->session_type) {
- case 'PRO':
- if($session->pro_id) {
- $pro = Pro::where('id', $session->pro_id)->first();
- if($pro) {
- $readBy = $pro->displayName() . ' (PRO)';
- }
- }
- break;
- case 'CLIENT':
- if($session->pro_id) {
- $client = Client::where('id', $session->client_id)->first();
- if($client) {
- $readBy = $client->displayName() . ' (CLIENT)';
- }
- }
- break;
- }
- }
- return $readBy;
- }
- }
|