+ // Remove non-specified domain if forced and we have a domain
+ if ($isFullUrl && $forceAppDomain) {
+ $explodedPath = explode('/', $path);
+ $path = implode('/', array_splice($explodedPath, 3));
+ }
+
+ // Return normal url path if not specified in config
+ if (config('app.url') === '') {
+ return url($path);
+ }
+
+ return rtrim(config('app.url'), '/') . '/' . $path;
+}
+
+/**
+ * Get an instance of the redirector.
+ * Overrides the default laravel redirect helper.
+ * Ensures it redirects even when the app is in a subdirectory.
+ *
+ * @param string|null $to
+ * @param int $status
+ * @param array $headers
+ * @param bool $secure
+ * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
+ */
+function redirect($to = null, $status = 302, $headers = [], $secure = null)
+{
+ if (is_null($to)) {
+ return app('redirect');
+ }
+
+ $to = baseUrl($to);
+
+ return app('redirect')->to($to, $status, $headers, $secure);
+}
+
+function icon($name, $attrs = [])
+{
+ $iconPath = resource_path('assets/icons/' . $name . '.svg');
+ $attrString = ' ';
+ foreach ($attrs as $attrName => $attr) {
+ $attrString .= $attrName . '="' . $attr . '" ';
+ }
+ $fileContents = file_get_contents($iconPath);
+ return str_replace('<svg', '<svg' . $attrString, $fileContents);
+}
+
+/**
+ * Generate a url with multiple parameters for sorting purposes.
+ * Works out the logic to set the correct sorting direction
+ * Discards empty parameters and allows overriding.
+ * @param $path
+ * @param array $data
+ * @param array $overrideData
+ * @return string
+ */
+function sortUrl($path, $data, $overrideData = [])
+{
+ $queryStringSections = [];
+ $queryData = array_merge($data, $overrideData);
+
+ // Change sorting direction is already sorted on current attribute
+ if (isset($overrideData['sort']) && $overrideData['sort'] === $data['sort']) {
+ $queryData['order'] = ($data['order'] === 'asc') ? 'desc' : 'asc';
+ } else {
+ $queryData['order'] = 'asc';
+ }
+
+ foreach ($queryData as $name => $value) {
+ $trimmedVal = trim($value);
+ if ($trimmedVal === '') {
+ continue;