|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SET\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Auth; |
|
6
|
|
|
use Illuminate\Support\Facades\Request; |
|
7
|
|
|
use Illuminate\Support\Facades\Storage; |
|
8
|
|
|
use Krucas\Notification\Facades\Notification; |
|
9
|
|
|
use SET\Attachment; |
|
10
|
|
|
use SET\Http\Requests\StoreNoteRequest; |
|
11
|
|
|
use SET\Http\Requests\UpdateNoteRequest; |
|
12
|
|
|
use SET\Note; |
|
13
|
|
|
use SET\User; |
|
14
|
|
|
|
|
15
|
|
|
class NoteController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
public function create(User $user) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->authorize('edit'); |
|
20
|
|
|
|
|
21
|
|
|
return view('note.create', compact('user')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
public function store(StoreNoteRequest $request, User $user) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->authorize('edit'); |
|
27
|
|
|
$data = $request->all(); |
|
28
|
|
|
$data['author_id'] = Auth::user()->id; |
|
29
|
|
|
|
|
30
|
|
|
$note = $user->notes()->create($data); |
|
31
|
|
|
|
|
32
|
|
|
if (Request::hasFile('files')) { |
|
33
|
|
|
Attachment::upload($note, Request::file('files'), $data['encrypt']); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
Notification::container()->success('Note successfully created'); |
|
37
|
|
|
|
|
38
|
|
|
return redirect()->action('UserController@show', $user->id); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function edit(User $user, $noteID) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->authorize('edit'); |
|
44
|
|
|
|
|
45
|
|
|
$note = Note::findOrFail($noteID); |
|
46
|
|
|
|
|
47
|
|
|
return view('note.edit', compact('user', 'note')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
View Code Duplication |
public function update(UpdateNoteRequest $request, $userID, $noteId) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->authorize('edit'); |
|
53
|
|
|
$note = Note::findOrFail($noteId); |
|
54
|
|
|
$note['author_id'] = Auth::user()->id; |
|
55
|
|
|
$data = $request->all(); |
|
56
|
|
|
$note->update($data); |
|
57
|
|
|
|
|
58
|
|
|
if (Request::hasFile('files')) { |
|
59
|
|
|
Attachment::upload($note, Request::file('files'), $data['encrypt']); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
Notification::container()->success('Note successfully updated'); |
|
63
|
|
|
|
|
64
|
|
|
return redirect()->action('UserController@show', $userID); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function destroy($userID, Note $note) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->authorize('edit'); |
|
70
|
|
|
|
|
71
|
|
|
$note->delete(); |
|
72
|
|
|
Storage::deleteDirectory('note_'.$note->id); |
|
73
|
|
|
|
|
74
|
|
|
return back(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|