Skip to content

Commit 8bb79d9

Browse files
chore: added a automatically random ID for short link if user not provides one
1 parent 2eaadaa commit 8bb79d9

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

app/Http/Controllers/LinkController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ public function store(CreateRequest $request)
7171
return back();
7272
}
7373

74+
$key = $request->key ? $request->key : Str::random(6);
75+
7476
$link = Link::create([
7577
'workspace_id' => $workspace->id,
7678
'domain' => $request->domain,
77-
'key' => $request->key,
79+
'key' => $key,
7880
'url' => $request->url,
79-
'link' => "https://{$request->domain}/{$request->key}",
81+
'link' => "https://{$request->domain}/{$key}",
8082
'utm_source' => $request->utm_source,
8183
'utm_medium' => $request->utm_medium,
8284
'utm_campaign' => $request->utm_campaign,
@@ -99,11 +101,13 @@ public function update($id, UpdateRequest $request)
99101

100102
$link = Link::where('workspace_id', $workspace->id)->where('id', $id)->firstOrFail();
101103

104+
$key = $request->key ? $request->key : Str::random(6);
105+
102106
$link->update([
103107
'domain' => $request->domain,
104-
'key' => $request->key,
108+
'key' => $key,
105109
'url' => $request->url,
106-
'link' => "https://{$request->domain}/{$request->key}",
110+
'link' => "https://{$request->domain}/{$key}",
107111
'utm_source' => $request->utm_source,
108112
'utm_medium' => $request->utm_medium,
109113
'utm_campaign' => $request->utm_campaign,

app/Http/Requests/Link/CreateRequest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ class CreateRequest extends FormRequest
2222
public function rules(): array
2323
{
2424
return [
25-
'key' => [
26-
'required',
27-
'string',
28-
'max:255',
29-
Rule::unique('links')->where('domain', $this->domain)->ignore($this->route('id')),
30-
],
25+
'key' => Rule::when(
26+
fn() => $this->key,
27+
[
28+
'required',
29+
'string',
30+
'max:255',
31+
Rule::unique('links')->where('domain', $this->domain)->ignore($this->route('id')),
32+
]
33+
),
34+
3135
'domain' => [
3236
'required',
3337
'string',

app/Http/Requests/Link/UpdateRequest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ class UpdateRequest extends FormRequest
2222
public function rules(): array
2323
{
2424
return [
25-
'key' => [
26-
'required',
27-
'string',
28-
'max:255',
29-
Rule::unique('links')->where('domain', $this->domain)->ignore($this->route('id')),
30-
],
25+
'key' => Rule::when(
26+
fn() => $this->key,
27+
[
28+
'required',
29+
'string',
30+
'max:255',
31+
Rule::unique('links')->where('domain', $this->domain)->ignore($this->route('id')),
32+
]
33+
),
34+
3135
'domain' => [
3236
'required',
3337
'string',

lang/php_en.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

resources/js/Components/Tag.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defineProps({
99

1010
<template>
1111
<div
12-
:class="`inline-flex bg-${tag.color}-100 text-${tag.color}-500 ring-1 ring-inset ring-${tag.color}-300 ring-opacity-40 text-xs truncate font-medium px-2 py-1 rounded`"
12+
:class="`inline-flex text-${tag.color}-500 ring-1 ring-inset ring-${tag.color}-300 ring-opacity-40 text-xs truncate font-medium px-2 py-1 rounded`"
1313
>
1414
{{ tag.name }}
1515
</div>

resources/js/Pages/Link/Index.vue

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ onMounted(() => {
247247
leave-to-class="transform opacity-0 scale-95"
248248
>
249249
<MenuItems
250-
class="absolute right-0 z-10 mt-2 w-56 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
250+
class="absolute right-0 z-10 mt-2 w-56 origin-top-right divide-y divide-gray-100 dark:divide-gray-700 rounded-md bg-white dark:bg-zinc-900 shadow-lg ring-1 ring-black dark:ring-zinc-700 ring-opacity-5 focus:outline-none"
251251
>
252252
<div class="py-1">
253253
<MenuItem v-slot="{ active }">
@@ -260,13 +260,13 @@ onMounted(() => {
260260
"
261261
:class="[
262262
active
263-
? 'bg-gray-100 text-gray-900'
264-
: 'text-gray-700',
265-
'group flex items-center px-4 py-2 text-sm',
263+
? 'bg-gray-100 dark:bg-zinc-800 text-gray-900 dark:text-zinc-300'
264+
: 'text-gray-700 dark:text-zinc-300',
265+
'flex items-center px-4 py-2 text-sm cursor-pointer',
266266
]"
267267
>
268268
<PhPencil
269-
class="mr-3 h-5 w-5 text-gray-400 group-hover:text-gray-500"
269+
class="mr-3 h-5 w-5 text-gray-400 dark:text-zinc-300"
270270
aria-hidden="true"
271271
/>
272272
Edit
@@ -279,13 +279,13 @@ onMounted(() => {
279279
"
280280
:class="[
281281
active
282-
? 'bg-gray-100 text-gray-900'
283-
: 'text-gray-700',
284-
'group flex items-center px-4 py-2 text-sm cursor-pointer',
282+
? 'bg-gray-100 dark:bg-zinc-800 text-gray-900 dark:text-zinc-300'
283+
: 'text-gray-700 dark:text-zinc-300',
284+
'flex items-center px-4 py-2 text-sm cursor-pointer',
285285
]"
286286
>
287287
<PhQrCode
288-
class="mr-3 h-5 w-5 text-gray-400 group-hover:text-gray-500"
288+
class="mr-3 h-5 w-5 text-gray-400 dark:text-zinc-300"
289289
aria-hidden="true"
290290
/>
291291
QR Code
@@ -303,13 +303,13 @@ onMounted(() => {
303303
"
304304
:class="[
305305
active
306-
? 'bg-gray-100 text-gray-900'
307-
: 'text-gray-700',
308-
'group flex items-center px-4 py-2 text-sm cursor-pointer',
306+
? 'bg-gray-100 dark:bg-zinc-800 text-gray-900 dark:text-zinc-300'
307+
: 'text-gray-700 dark:text-zinc-300',
308+
'flex items-center px-4 py-2 text-sm cursor-pointer',
309309
]"
310310
>
311311
<PhCopy
312-
class="mr-3 h-5 w-5 text-gray-400 group-hover:text-gray-500"
312+
class="mr-3 h-5 w-5 text-gray-400 dark:text-zinc-300"
313313
aria-hidden="true"
314314
/>
315315
Copy Link ID
@@ -334,9 +334,9 @@ onMounted(() => {
334334
"
335335
:class="[
336336
active
337-
? 'bg-red-50 text-red-600'
337+
? 'bg-zinc-100 dark:bg-zinc-800 text-red-600'
338338
: 'text-red-500',
339-
'group flex items-center px-4 py-2 text-sm cursor-pointer',
339+
'flex items-center px-4 py-2 text-sm cursor-pointer',
340340
]"
341341
>
342342
<PhTrash

0 commit comments

Comments
 (0)