99 lines
2.9 KiB
PHP
Executable File
99 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Ticket extends Model
|
|
{
|
|
use CrudTrait;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| GLOBAL VARIABLES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
protected $table = 'tickets';
|
|
// protected $primaryKey = 'id';
|
|
// public $timestamps = false;
|
|
// protected $guarded = ['id'];
|
|
protected $fillable = [
|
|
'client_id',
|
|
'status_id',
|
|
'title',
|
|
'content',
|
|
'category_id',
|
|
'last_sender',
|
|
'application_id',
|
|
'broker_application_id'
|
|
];
|
|
// protected $hidden = [];
|
|
// protected $dates = [];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| FUNCTIONS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function messagesOfTicket(){
|
|
return '<a class="btn btn-sm btn-link" href="'. backpack_url('chat') .'?ticket_id='.$this->id.'" data-toggle="tooltip">
|
|
<svg xmlns="http://www.w3.org/2000/svg" style="width:15px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
|
</svg> Chat</a>';
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| RELATIONS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function account(){
|
|
return $this->belongsTo(Account::class, 'client_id');
|
|
}
|
|
|
|
public function category(){
|
|
return $this->belongsTo(Category::class, 'category_id');
|
|
}
|
|
|
|
public function status(){
|
|
return $this->belongsTo(Status::class, 'status_id');
|
|
}
|
|
|
|
public function messages(){
|
|
return $this->hasMany(Message::class);
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| SCOPES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function scopeOpen($query)
|
|
{
|
|
return $query->whereHas('status', function ($q) {
|
|
$q->where('name', 'Open');
|
|
});
|
|
}
|
|
|
|
public function scopeClosed($query)
|
|
{
|
|
return $query->whereHas('status', function ($q) {
|
|
$q->where('name', 'Closed');
|
|
});
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| ACCESSORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| MUTATORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
}
|