1
|
|
|
<?php |
2
|
|
|
namespace Xetaravel\Models\Repositories; |
3
|
|
|
|
4
|
|
|
use Illuminate\Support\Collection; |
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use Xetaravel\Models\DiscussThread; |
7
|
|
|
|
8
|
|
|
class DiscussThreadRepository |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Create the new thread and save it. |
13
|
|
|
* |
14
|
|
|
* @param array $data The data used to create the thread. |
15
|
|
|
* |
16
|
|
|
* @return \Xetaravel\Models\DiscussThread |
17
|
|
|
*/ |
18
|
|
|
public static function create(array $data): DiscussThread |
19
|
|
|
{ |
20
|
|
|
$thread = [ |
21
|
|
|
'title' => $data['title'], |
22
|
|
|
'category_id' => $data['category_id'], |
23
|
|
|
'content' => $data['content'] |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
$user = Auth::user(); |
27
|
|
|
|
28
|
|
|
if ($user->hasPermission('manage.discuss.threads')) { |
29
|
|
|
$thread += [ |
30
|
|
|
'is_locked' => isset($data['is_locked']) ? true : false, |
31
|
|
|
'is_pinned' => isset($data['is_pinned']) ? true : false, |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return DiscussThread::create($thread); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Update the article data and save it. |
40
|
|
|
* |
41
|
|
|
* @param array $data The data used to update the article. |
42
|
|
|
* @param \Xetaravel\Models\Article $article The article to update. |
|
|
|
|
43
|
|
|
* |
44
|
|
|
* @return \Xetaravel\Models\Article |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public static function update(array $data, Article $article): Article |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$article->title = $data['title']; |
49
|
|
|
$article->category_id = $data['category_id']; |
50
|
|
|
$article->is_display = isset($data['is_display']) ? true : false; |
51
|
|
|
$article->content = $data['content']; |
52
|
|
|
$article->save(); |
53
|
|
|
|
54
|
|
|
return $article; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.