Skip to content

Commit 5380544

Browse files
committed
Expanded controller for custom icon
Expanded user controller to save the custom icon of individual buttons for the Button Editor. I wanted to put the saving part into its own controller, but I wasn't able to implement this because I couldn't put two controllers on one page via the route in web.php, and to my knowledge this is impossible. So I had to do some trickery to get this working. If I hadn't implemented the if-else statement, one value couldn't be saved without a NULL error violation. This will be used to display a custom icon via Font Awesome. See: https://blog.littlelink-custom.com/upcoming-features/ And: https://blog.littlelink-custom.com/progress-of-the-new-button-editor/
1 parent 978add4 commit 5380544

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

app/Http/Controllers/UserController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function showLink(request $request)
201201

202202
}
203203

204-
//Show custom CSS
204+
//Show custom CSS + custom icon
205205
public function showCSS(request $request)
206206
{
207207
$linkId = $request->id;
@@ -226,7 +226,6 @@ public function editLink(request $request)
226226
'link' => 'required',
227227
'title' => 'required',
228228
'button' => 'required',
229-
//'custom_css' => 'required',
230229
]);
231230

232231
if (stringStartsWith($request->link,'http://') == 'true' or stringStartsWith($request->link,'https://') == 'true' or stringStartsWith($request->link,'mailto:') == 'true')
@@ -241,7 +240,6 @@ public function editLink(request $request)
241240
$order = $request->order;
242241
$button = $request->button;
243242
$linkId = $request->id;
244-
//$custom_css = $request->custom_css;
245243

246244
$buttonId = Button::select('id')->where('name' , $button)->value('id');
247245

@@ -250,18 +248,20 @@ public function editLink(request $request)
250248
return redirect('/studio/links');
251249
}
252250

253-
//Save edit custom CSS
251+
//Save edit custom CSS + custom icon
254252
public function editCSS(request $request)
255253
{
256-
$request->validate([
257-
'custom_css' => 'required',
258-
]);
259-
260254
$linkId = $request->id;
255+
$custom_icon = $request->custom_icon;
261256
$custom_css = $request->custom_css;
262257

258+
if ($request->custom_css == "" and $request->custom_icon =! "") {
259+
Link::where('id', $linkId)->update(['custom_icon' => $custom_icon]);
260+
} elseif ($request->custom_icon == "" and $request->custom_css =! "") {
263261
Link::where('id', $linkId)->update(['custom_css' => $custom_css]);
264-
262+
} else {
263+
Link::where('id', $linkId)->update([]);
264+
}
265265
return header("Refresh:0");
266266
}
267267

0 commit comments

Comments
 (0)