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/
This commit is contained in:
Julian Prieber 2022-04-13 16:49:44 +02:00
parent 978add4b7b
commit 53805444aa
1 changed files with 9 additions and 9 deletions

View File

@ -201,7 +201,7 @@ class UserController extends Controller
}
//Show custom CSS
//Show custom CSS + custom icon
public function showCSS(request $request)
{
$linkId = $request->id;
@ -226,7 +226,6 @@ class UserController extends Controller
'link' => 'required',
'title' => 'required',
'button' => 'required',
//'custom_css' => 'required',
]);
if (stringStartsWith($request->link,'http://') == 'true' or stringStartsWith($request->link,'https://') == 'true' or stringStartsWith($request->link,'mailto:') == 'true')
@ -241,7 +240,6 @@ class UserController extends Controller
$order = $request->order;
$button = $request->button;
$linkId = $request->id;
//$custom_css = $request->custom_css;
$buttonId = Button::select('id')->where('name' , $button)->value('id');
@ -250,18 +248,20 @@ class UserController extends Controller
return redirect('/studio/links');
}
//Save edit custom CSS
//Save edit custom CSS + custom icon
public function editCSS(request $request)
{
$request->validate([
'custom_css' => 'required',
]);
$linkId = $request->id;
$custom_icon = $request->custom_icon;
$custom_css = $request->custom_css;
if ($request->custom_css == "" and $request->custom_icon =! "") {
Link::where('id', $linkId)->update(['custom_icon' => $custom_icon]);
} elseif ($request->custom_icon == "" and $request->custom_css =! "") {
Link::where('id', $linkId)->update(['custom_css' => $custom_css]);
} else {
Link::where('id', $linkId)->update([]);
}
return header("Refresh:0");
}