|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Afrittella\BackProject\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Afrittella\BackProject\Exceptions\NotFoundException; |
|
6
|
|
|
use Afrittella\BackProject\Http\Requests\AttachmentAdd; |
|
7
|
|
|
use Afrittella\BackProject\Repositories\Attachments; |
|
8
|
|
|
use Afrittella\BackProject\Repositories\Criteria\Attachments\ByUser; |
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
use Illuminate\Support\Facades\Auth; |
|
11
|
|
|
use Prologue\Alerts\Facades\Alert; |
|
12
|
|
|
|
|
13
|
|
|
class AttachmentsController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
public function __construct() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->middleware('admin'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function index(Attachments $attachments) |
|
21
|
|
|
{ |
|
22
|
|
|
// pushCriteria is a method from Repository Pattern |
|
23
|
|
|
$attachments->pushCriteria(new ByUser()); |
|
24
|
|
|
return view('back-project::attachments.index')->with('attachments', $attachments->all()); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param Attachments $attachments |
|
30
|
|
|
* @param $id |
|
31
|
|
|
* @return $this |
|
32
|
|
|
*/ |
|
33
|
|
|
public function edit(Attachments $attachments, $id) |
|
34
|
|
|
{ |
|
35
|
|
|
$attachment = $attachments->find($id); |
|
36
|
|
|
|
|
37
|
|
|
$this->bCAuthorize('update', $attachment); |
|
38
|
|
|
|
|
39
|
|
|
return view('back-project::attachments.edit')->with('attachment', $attachment); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
public function store(AttachmentAdd $request, Attachments $attachments) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$user = Auth::user(); |
|
45
|
|
|
|
|
46
|
|
|
$success = $attachments->create(array_merge($request->all(), ['user_id' => $user->id])); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
Alert::add('success', trans('back-project::base.image_uploaded'))->flash(); |
|
49
|
|
|
|
|
50
|
|
|
return response()->json([ |
|
51
|
|
|
'success' => true, |
|
52
|
|
|
'message' => trans('back-project::base.image_uploaded') |
|
53
|
|
|
]); |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
public function update(Request $request, Attachments $attachments, $id) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
$attachment = $attachments->find($id); |
|
60
|
|
|
|
|
61
|
|
|
$this->bCAuthorize('update', $attachment); |
|
62
|
|
|
|
|
63
|
|
|
$attachment = $attachments->update($request->all(), $id); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
Alert::add('success', trans('back-project::crud.model_updated', ['model' => trans('back-project::media.image')]))->flash(); |
|
66
|
|
|
|
|
67
|
|
|
return redirect(route('bp.attachments.index')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function delete(Attachments $attachments, $id) |
|
71
|
|
|
{ |
|
72
|
|
|
$attachment = $attachments->find($id); |
|
73
|
|
|
|
|
74
|
|
|
$this->bCAuthorize('delete', $attachment); |
|
75
|
|
|
|
|
76
|
|
|
$attachments->delete($id); |
|
77
|
|
|
|
|
78
|
|
|
Alert::add('success', trans('back-project::crud.model_deleted', ['model' => trans('back-project::media.image')]))->flash(); |
|
79
|
|
|
|
|
80
|
|
|
return back(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
View Code Duplication |
public function setMain(Attachments $attachments, $id) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$attachment = $attachments->find($id); |
|
86
|
|
|
|
|
87
|
|
|
$this->bCAuthorize('update', $attachment); |
|
88
|
|
|
|
|
89
|
|
|
$data = [ |
|
90
|
|
|
'is_main' => 1 |
|
91
|
|
|
]; |
|
92
|
|
|
|
|
93
|
|
|
$attachments->update($data, $id); |
|
94
|
|
|
|
|
95
|
|
|
Alert::add('success', trans('back-project::crud.model_updated', ['model' => trans('back-project::media.image')]))->flash(); |
|
96
|
|
|
|
|
97
|
|
|
return redirect(route('bp.attachments.index')); |
|
98
|
|
|
} |
|
99
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: