1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
class User_contact extends Base_Model { |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The database table used by the model. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $table = 'user_contacts'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Attributes that should be mass-assignable. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $fillable = ['contact_type_id', 'value', 'preferred', 'security_user_id', 'modified_user_id', 'modified', 'created_user_id', 'created']; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The attributes excluded from the model's JSON form. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $hidden = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The attributes that should be casted to native types. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $casts = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The attributes that should be mutated to dates. |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $dates = ['modified', 'created']; |
43
|
|
|
|
44
|
|
|
public static function createOrUpdate($data,$user){ |
45
|
|
|
|
46
|
|
|
if(!is_null($data['contact'])){ |
47
|
|
|
$exists = self::where('security_user_id', $data->id) |
48
|
|
|
->where('value',$data['contact']) |
49
|
|
|
->first(); |
50
|
|
|
|
51
|
|
|
if(is_null($exists)){ |
52
|
|
|
$data = [ |
53
|
|
|
'security_user_id' => $data->id, |
54
|
|
|
'value' => $data['contact'], |
55
|
|
|
'contact_type_id' => 13, |
56
|
|
|
'created' => now(), |
57
|
|
|
'created_user_id' => $user, |
58
|
|
|
'preferred' => 1 |
59
|
|
|
]; |
60
|
|
|
self::updateOrCreate($data); |
61
|
|
|
}else{ |
62
|
|
|
$exists = $exists->toArray(); |
63
|
|
|
$exists['preferred'] = 1; |
64
|
|
|
$exists['value'] = $data['contact']; |
65
|
|
|
$exists['modified_user_id'] = $user; |
66
|
|
|
$exists['contact_type_id'] = 13; |
67
|
|
|
$exists['modified'] = now(); |
68
|
|
|
self::updateOrCreate($exists); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |