|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
# == Schema Information |
|
13
|
|
|
# |
|
14
|
|
|
# Table name: owners |
|
15
|
|
|
# |
|
16
|
|
|
# id :integer not null, primary key |
|
17
|
|
|
# name :string(255) not null |
|
18
|
|
|
# path :string(255) not null |
|
19
|
|
|
# user_id :integer |
|
20
|
|
|
# created_at :datetime |
|
21
|
|
|
# updated_at :datetime |
|
22
|
|
|
# type :string(255) |
|
23
|
|
|
# description :string(255) default(""), not null |
|
24
|
|
|
# avatar :string(255) |
|
25
|
|
|
# public :boolean default(FALSE) |
|
26
|
|
|
# |
|
27
|
|
|
|
|
28
|
|
|
namespace Gitamin\Models; |
|
29
|
|
|
|
|
30
|
|
|
use AltThree\Validator\ValidatingTrait; |
|
31
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
32
|
|
|
use Illuminate\Support\Facades\Auth; |
|
33
|
|
|
|
|
34
|
|
|
class Owner extends Model |
|
35
|
|
|
{ |
|
36
|
|
|
use ValidatingTrait; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The attributes that should be casted to native types. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string[] |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $casts = [ |
|
44
|
|
|
'id' => 'int', |
|
45
|
|
|
'name' => 'string', |
|
46
|
|
|
'path' => 'string', |
|
47
|
|
|
'user_id' => 'int', |
|
48
|
|
|
'type' => 'string', |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The fillable properties. |
|
53
|
|
|
* |
|
54
|
|
|
* @var string[] |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $fillable = ['name', 'path', 'user_id', 'description', 'type']; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The validation rules. |
|
60
|
|
|
* |
|
61
|
|
|
* @var string[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public $rules = [ |
|
64
|
|
|
'name' => 'required|string', |
|
65
|
|
|
'path' => 'required|string|max:15', |
|
66
|
|
|
'user_id' => 'int', |
|
67
|
|
|
'type' => 'string', |
|
68
|
|
|
'description' => 'string', |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* A owner can have many projects. |
|
73
|
|
|
* |
|
74
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
75
|
|
|
*/ |
|
76
|
|
|
public function projects() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->hasMany(Project::class, 'owner_id', 'id'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Finds all my owners. |
|
83
|
|
|
* |
|
84
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query |
|
85
|
|
|
* |
|
86
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
|
87
|
|
|
*/ |
|
88
|
|
|
public function scopeMine($query) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
//return $query->where('user_id', Auth::user()->id); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.