-
Notifications
You must be signed in to change notification settings - Fork 106
/
Project.php
78 lines (68 loc) · 1.49 KB
/
Project.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
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use RecordsActivity;
/**
* Attributes to guard against mass assignment.
*
* @var array
*/
protected $guarded = [];
/**
* The path to the project.
*
* @return string
*/
public function path()
{
return "/projects/{$this->id}";
}
/**
* The owner of the project.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function owner()
{
return $this->belongsTo(User::class);
}
/**
* The tasks associated with the project.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function tasks()
{
return $this->hasMany(Task::class);
}
/**
* Add a task to the project.
*
* @param string $body
* @return \Illuminate\Database\Eloquent\Model
*/
public function addTask($body)
{
return $this->tasks()->create(compact('body'));
}
/**
* Invite a user to the project.
*
* @param \App\User $user
*/
public function invite(User $user)
{
$this->members()->attach($user);
}
/**
* Get all members that are assigned to the team.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function members()
{
return $this->belongsToMany(User::class, 'project_members')->withTimestamps();
}
}