PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.3.0
Fluent Support – Helpdesk & Customer Support Ticket System v2.3.0
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Models / TicketTag.php

TicketTag.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.3.0, at app/Models/TicketTag.php

45 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Models;
4
5 class TicketTag extends Tag
6 {
7 protected static $type = 'ticket_tag';
8
9 public static function boot()
10 {
11 parent::boot();
12
13 static::creating(function ($model) {
14 $model->tag_type = static::$type;
15 if(empty($model->created_by) && $userId = get_current_user_id()) {
16 $model->created_by = $userId;
17 }
18
19 $model->slug = static::slugify($model->title);
20 });
21
22 static::addGlobalScope(function ($builder) {
23 $builder->where('tag_type', static::$type);
24 });
25 }
26
27
28 public static function slugify($title)
29 {
30 $slug = sanitize_title($title, 'ticket-tag', 'display');
31 if (TicketTag::where('slug', $slug)->first()) {
32 $slug .= '-' . time();
33 }
34 return $slug;
35 }
36
37 public function tickets()
38 {
39 return $this->belongsToMany(
40 __NAMESPACE__.'\Ticket', 'fs_tag_pivot', 'tag_id', 'source_id'
41 )->where('source_type', 'ticket_tag');
42 }
43
44 }
45