1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use App\Doctor; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
|
8
|
|
|
class Articles extends Model |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $table = 'articles'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
public $primaryKey = 'id'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
public $timestamps = true; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $dates = [ |
29
|
|
|
'created_at', |
30
|
|
|
'updated_at' |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
35
|
|
|
*/ |
36
|
|
|
public function admin() { |
37
|
|
|
return $this->belongsTo('App\Admin'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
43
|
|
|
*/ |
44
|
|
|
public function doctor() { |
45
|
|
|
return $this->belongsTo('App\Doctor'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $id |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function writer() { |
53
|
|
|
$adminId = $this->getAttributeValue('admin_id'); |
54
|
|
|
$doctorId = $this->getAttributeValue('doctor_id'); |
55
|
|
|
|
56
|
|
|
$writer = ['role', 'data']; |
57
|
|
|
|
58
|
|
|
if($adminId != null) { |
59
|
|
|
$writer['role'] = "Admin"; |
60
|
|
|
$writer['data'] = Admin::find($adminId); |
61
|
|
|
} elseif($doctorId != null) { |
62
|
|
|
$writer['role'] = "Dokter"; |
63
|
|
|
$writer['data'] = Doctor::find($doctorId); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $writer; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $str |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function cutStr($str) |
74
|
|
|
{ |
75
|
|
|
if (strlen($str) > 200){ |
76
|
|
|
return substr($str,0,200) . "..."; |
77
|
|
|
} |
78
|
|
|
return $str; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $str |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getCat($str) |
86
|
|
|
{ |
87
|
|
|
switch ($str) { |
88
|
|
|
case "penyakit": return "Penyakit"; break; |
|
|
|
|
89
|
|
|
case "obat": return "Obat - obatan"; break; |
90
|
|
|
case "hidup-sehat": return "Hidup Sehat"; break; |
91
|
|
|
case "keluarga": return "Keluarga"; break; |
92
|
|
|
case "kesehatan": return "Kesehatan"; break; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.