|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\VendorFormRequest; |
|
6
|
|
|
use App\Http\Requests\VendorUpdateFormRequest; |
|
7
|
|
|
use App\Repositories\VendorRepository; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
|
|
10
|
|
|
class VendorController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var VendorRepository |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $vendors; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* VendorController constructor. |
|
19
|
|
|
* @param VendorRepository $vendorRepository |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(VendorRepository $vendorRepository) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->vendors = $vendorRepository; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function index() |
|
27
|
|
|
{ |
|
28
|
|
|
$vendors = $this->vendors->getPublic($paginate = 9); |
|
29
|
|
|
|
|
30
|
|
|
return view('vendors.index', compact('vendors')); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create vendor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param VendorFormRequest $request |
|
37
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
38
|
|
|
*/ |
|
39
|
|
|
public function postCreate(VendorFormRequest $request) |
|
40
|
|
|
{ |
|
41
|
|
|
$vendor = $this->vendors->create($request->all()); |
|
42
|
|
|
|
|
43
|
|
|
return redirect()->route('view_vendor', ['vendor' => $vendor->slug]); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create form for vendor. |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getCreate() |
|
52
|
|
|
{ |
|
53
|
|
|
return view('vendors.create'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Show vendor. |
|
58
|
|
|
* |
|
59
|
|
|
* @param $vendor |
|
60
|
|
|
* @return mixed |
|
61
|
|
|
*/ |
|
62
|
|
|
public function show($vendor) |
|
63
|
|
|
{ |
|
64
|
|
|
return view('vendors.show')->withItem($vendor); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Edit form for vendor. |
|
69
|
|
|
* |
|
70
|
|
|
* @param $vendor |
|
71
|
|
|
* @return mixed |
|
72
|
|
|
*/ |
|
73
|
|
|
public function edit($vendor) |
|
74
|
|
|
{ |
|
75
|
|
|
return view('vendors.edit')->withItem($vendor); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Update vendor. |
|
80
|
|
|
* |
|
81
|
|
|
* @param VendorUpdateFormRequest $request |
|
82
|
|
|
* @param $vendor |
|
83
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
84
|
|
|
*/ |
|
85
|
|
|
public function update(VendorUpdateFormRequest $request, $vendor) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->vendors->update($vendor, $request->all()); |
|
88
|
|
|
|
|
89
|
|
|
return redirect()->route('view_vendor', ['slug' => $vendor->slug]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function vote_vendor(Request $request, $vendor) |
|
93
|
|
|
{ |
|
94
|
|
|
if($request->get('like_type') == 'like') |
|
95
|
|
|
{ |
|
96
|
|
View Code Duplication |
if($vendor->wasLiked('like')) { |
|
|
|
|
|
|
97
|
|
|
$vendor->unlike('like'); |
|
98
|
|
|
} else { |
|
99
|
|
|
if($vendor->wasLiked('dislike')) |
|
100
|
|
|
$vendor->unlike('dislike'); |
|
101
|
|
|
|
|
102
|
|
|
$vendor->like('like'); |
|
103
|
|
|
} |
|
104
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
105
|
|
|
if($vendor->wasLiked('dislike')) { |
|
106
|
|
|
$vendor->unlike('dislike'); |
|
107
|
|
|
} else { |
|
108
|
|
|
if($vendor->wasLiked('like')) |
|
109
|
|
|
$vendor->unlike('like'); |
|
110
|
|
|
|
|
111
|
|
|
$vendor->like('dislike'); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
if($vendor->wasLiked('like')){ |
|
115
|
|
|
|
|
116
|
|
|
$was_liked = 'like'; |
|
117
|
|
|
} |
|
118
|
|
|
elseif($vendor->wasLiked('dislike')) { |
|
119
|
|
|
|
|
120
|
|
|
$was_liked = 'unlike'; |
|
121
|
|
|
} |
|
122
|
|
|
else{ |
|
123
|
|
|
$was_liked = "not_liked"; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if($vendor->likes()->count()) |
|
127
|
|
|
{ |
|
128
|
|
|
$positive_like_percent = |
|
129
|
|
|
($vendor->likes()->count() - $vendor->getLikes('dislike')->count()) / $vendor->likes()->count() * 100; |
|
130
|
|
|
} |
|
131
|
|
|
else { |
|
132
|
|
|
$positive_like_percent = 0; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
return json_encode([ |
|
137
|
|
|
'likes' => $vendor->getLikes('like')->count(), |
|
138
|
|
|
'dislikes' => $vendor->getLikes('dislike')->count(), |
|
139
|
|
|
'likes_count' => $vendor->likes()->count(), |
|
140
|
|
|
'likes_percent' => $positive_like_percent, |
|
141
|
|
|
'was_liked' => $was_liked |
|
142
|
|
|
]); |
|
143
|
|
|
} |
|
144
|
|
|
} |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.