|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use App\Orders\CreateWalletOrder; |
|
6
|
|
|
use App\Services\ImageProcessor; |
|
7
|
|
|
use App\Vendor; |
|
8
|
|
|
use Auth; |
|
9
|
|
|
|
|
10
|
|
|
class VendorRepository extends Repository |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return Vendor |
|
14
|
|
|
*/ |
|
15
|
|
|
public function getModel() |
|
16
|
|
|
{ |
|
17
|
|
|
return new Vendor(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Create method. |
|
22
|
|
|
* |
|
23
|
|
|
* @param array $data |
|
24
|
|
|
* @return Vendor |
|
25
|
|
|
*/ |
|
26
|
|
|
public function create(array $data) |
|
27
|
|
|
{ |
|
28
|
|
|
$vendor = self::getModel() |
|
29
|
|
|
->create([ |
|
30
|
|
|
'user_id' => Auth::id(), |
|
31
|
|
|
'name' => $data['name'], |
|
32
|
|
|
'email' => $data['email'], |
|
33
|
|
|
'phone' => $data['phone'], |
|
34
|
|
|
'description' => $data['description'] |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
(new CreateWalletOrder(\Auth::user())); |
|
38
|
|
|
|
|
39
|
|
|
if (isset($data['image'])) { |
|
40
|
|
|
$file = $data['image']; |
|
41
|
|
|
$location = 'upload/vendors/' . $vendor->id; |
|
|
|
|
|
|
42
|
|
|
$processor = new ImageProcessor(); |
|
43
|
|
|
$processor->uploadAndCreate($file, $vendor, $data, $location); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $vendor; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Update method. |
|
51
|
|
|
* |
|
52
|
|
|
* @param Vendor $vendor |
|
53
|
|
|
* @param $data |
|
54
|
|
|
* @throws \Exception |
|
55
|
|
|
*/ |
|
56
|
|
|
public function update(Vendor $vendor, $data) |
|
57
|
|
|
{ |
|
58
|
|
|
$vendor->fill([ |
|
59
|
|
|
'name' => $data['name'], |
|
60
|
|
|
'email' => $data['email'], |
|
61
|
|
|
'description' => $data['description'], |
|
62
|
|
|
'phone' => $data['phone'] |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
|
|
if (isset($data['image'])) { |
|
66
|
|
|
$file = $data['image']; |
|
67
|
|
|
$location = 'upload/vendors/' . $vendor->id; |
|
|
|
|
|
|
68
|
|
|
$processor = new ImageProcessor(); |
|
69
|
|
|
$processor->destroy($vendor->images()->first()); // delete old logo. |
|
70
|
|
|
|
|
71
|
|
|
$processor->uploadAndCreate($file, $vendor, $data, $location); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$vendor->save(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getPublic($paginate = 9) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getModel() |
|
|
|
|
|
|
80
|
|
|
->active() //todo: get popular first... |
|
81
|
|
|
->orderBy('id', 'DESC') |
|
82
|
|
|
->paginate($paginate); |
|
83
|
|
|
} |
|
84
|
|
|
} |
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.