Skip to content

Commit ad744db

Browse files
committed
Update UserController.php
1 parent adee9cc commit ad744db

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

app/Http/Controllers/UserController.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cohensive\OEmbed\Facades\OEmbed;
88
use Illuminate\Support\Facades\Schema;
99
use Illuminate\Support\Facades\Route;
10+
use Illuminate\Support\Facades\Response;
1011
use JeroenDesloovere\VCard\VCard;
1112

1213
use Auth;
@@ -479,25 +480,21 @@ public function clickNumber(request $request)
479480
}
480481

481482
//Download Vcard
482-
public function vcard(Request $request)
483+
public function vcard(request $request)
483484
{
484485
$linkId = $request->id;
485-
$link = Link::findOrFail($linkId); // find the link with the given ID or throw an exception
486-
$buttonValue = $link->button_value;
487-
$content = $link->content;
488486

489-
Link::where('id', $linkId)->increment('click_number', 1);
487+
// Find the link with the specified ID
488+
$link = Link::findOrFail($linkId);
490489

491-
// build the vCard string
492-
$vCard = "BEGIN:VCARD\r\nVERSION:3.0\r\n";
493-
$vCard .= "FN:$buttonValue\r\n";
494-
$vCard .= "NOTE:$content\r\n";
495-
$vCard .= "END:VCARD\r\n";
490+
// Set the response headers to indicate that a VCard file should be downloaded
491+
$headers = [
492+
'Content-Type' => 'text/vcard',
493+
'Content-Disposition' => 'attachment; filename="vcard.vcf"',
494+
];
496495

497-
// return the vCard content as a downloadable response
498-
return response($vCard)
499-
->header('Content-Type', 'text/vcard')
500-
->header('Content-Disposition', 'attachment; filename=vcard.vcf');
496+
// Return the link's content as a downloadable file
497+
return Response::make($link->link, 200, $headers);
501498
}
502499

503500
//Show link, click number, up link in links page

0 commit comments

Comments
 (0)