-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLanguage.php
138 lines (128 loc) · 3.24 KB
/
Language.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Class Language
*
* @category Worketic
*
* @package Worketic
* @author Amentotech <[email protected]>
* @license http://www.amentotech.com Amentotech
* @link http://www.amentotech.com
*/
namespace App;
use DB;
use Illuminate\Database\Eloquent\Model;
/**
* Class Language
*
*/
class Language extends Model
{
/**
* Fillables for the database
*
* @access protected
* @var array $fillable
*/
protected $fillable = array(
'title', 'slug', 'description',
);
/**
* Protected Date
*
* @access protected
* @var array $dates
*/
protected $dates = [
'created_at',
'updated_at',
];
/**
* Get all of the users that are assigned this category.
*
* @return relation
*/
public function users()
{
return $this->morphedByMany('App\User', 'langable');
}
/**
* Get all of the users that are assigned this category.
*
* @return relation
*/
public function jobs()
{
return $this->morphedByMany('App\Job', 'langable');
}
/**
* Get all of the services that are assigned this category.
*
* @return relation
*/
public function services()
{
return $this->morphedByMany('App\Service', 'langable');
}
/**
* Set slug before saving in DB
*
* @param string $value value
*
* @access public
*
* @return string
*/
public function setSlugAttribute($value)
{
if (!empty($value)) {
$temp = str_slug($value, '-');
if (!Language::all()->where('slug', $temp)->isEmpty()) {
$i = 1;
$new_slug = $temp . '-' . $i;
while (!Language::all()->where('slug', $new_slug)->isEmpty()) {
$i++;
$new_slug = $temp . '-' . $i;
}
$temp = $new_slug;
}
$this->attributes['slug'] = $temp;
}
}
/**
* For saving Languages in Database
*
* @param string $request string
*
* @return \Illuminate\Http\Response
*/
public function saveLanguages($request)
{
if (!empty($request)) {
$this->title = filter_var($request['language_title'], FILTER_SANITIZE_STRING);
$this->slug = filter_var($request['language_title'], FILTER_SANITIZE_STRING);
$this->description = filter_var($request['language_desc'], FILTER_SANITIZE_STRING);
return $this->save();
}
}
/**
* For updating languages
*
* @param string $request string
* @param int $id integer
*
* @return \Illuminate\Http\Response
*/
public function updateLanguage($request, $id)
{
if (!empty($request)) {
$langs = self::find($id);
if ($langs->title != $request['language_title']) {
$langs->slug = filter_var($request['language_title'], FILTER_SANITIZE_STRING);
}
$langs->title = filter_var($request['language_title'], FILTER_SANITIZE_STRING);
$langs->description = filter_var($request['language_desc'], FILTER_SANITIZE_STRING);
$langs->save();
}
}
}