You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/Http/Livewire/ImagePicker.php
+88-3Lines changed: 88 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -12,32 +12,108 @@ class ImagePicker extends Component
12
12
{
13
13
use WithFileUploads, HasImageUploads, AuthorizesRequests;
14
14
15
+
/**
16
+
* Uploaded image file
17
+
* @var $image
18
+
*/
15
19
public$image;
20
+
21
+
/**
22
+
* Existing image URL (if the model already has an image)
23
+
* @var string|null
24
+
*/
16
25
public$existing_image_url;
26
+
27
+
/**
28
+
* A kebab-case unique identifier for each component
29
+
* @var string
30
+
* for the Livewire wire:key directive to identify the DOM elements when multiple instances of the component exist
31
+
* Example: "banner-img"
32
+
*/
17
33
public$custom_key;
34
+
35
+
/**
36
+
* Additional instructions for the image file selection
37
+
* @var string|null
38
+
* Example: "This photo will appear on your profile page and as your application profile image - please use a high-quality image (300x300 pixels or larger)."
39
+
*
40
+
*/
18
41
public$custom_msg;
42
+
43
+
/**
44
+
* Model instance that has an image is associated
45
+
* @var \Illuminate\Database\Eloquent\Model
46
+
*/
19
47
public$model;
48
+
49
+
/**
50
+
* Method on the model used to save the image
51
+
* @var string
52
+
*/
20
53
public$save_function;
54
+
55
+
/**
56
+
* Parameters passed to the save function
57
+
* @var array
58
+
*/
21
59
public$save_params;
60
+
61
+
/**
62
+
* The parameter name expected by the save function for the uploaded image
63
+
* @var string
64
+
*/
22
65
public$image_param_name;
66
+
67
+
/**
68
+
* Callback function to execute after saving the image
69
+
* @var string|null
70
+
*/
23
71
public$callback_function;
72
+
73
+
/**
74
+
* Parameters for the callback function
75
+
* @var array
76
+
*/
24
77
public$callback_params;
78
+
79
+
/**
80
+
* Additional blade partial view to display below the image preview
81
+
* @var string|null
82
+
*/
25
83
public$partial_view;
84
+
85
+
/**
86
+
* Route to redirect to after saving the image
87
+
* @var string
88
+
*/
26
89
public$redirect_route;
90
+
91
+
/**
92
+
* Flash message displayed after saving the image
93
+
* @var string|null
94
+
*/
27
95
public$message;
96
+
97
+
/**
98
+
* Authorization parameters for checking user permissions
99
+
* @var array $auth_params
100
+
*/
28
101
public$auth_params;
29
102
30
103
publicfunctionmount()
31
104
{
32
-
if (isset($this->save_function)) {
105
+
if (isset($this->save_function)) {// Validates save function only if set
33
106
$this->validateCallUserFunc('save_function');
34
107
}
35
108
36
-
if (isset($this->callback_function)) {
109
+
if (isset($this->callback_function)) {// Validates callback function only if set
37
110
$this->validateCallUserFunc('callback_function');
38
111
}
39
112
}
40
113
114
+
/**
115
+
* Validates the image after a file has been selected and stores the updated image in the save function parameters for uploading
116
+
*/
41
117
publicfunctionupdatedImage()
42
118
{
43
119
if ($this->image) {
@@ -53,17 +129,26 @@ public function save()
53
129
{
54
130
$this->authorize(...$this->auth_params);
55
131
132
+
// Calls the model's save function if an image is uploaded
0 commit comments