Update UserController.php

This commit is contained in:
Julian Prieber 2023-03-28 13:45:54 +02:00
parent adee9ccaec
commit ad744dbbaa

View File

@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Hash;
use Cohensive\OEmbed\Facades\OEmbed; use Cohensive\OEmbed\Facades\OEmbed;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Response;
use JeroenDesloovere\VCard\VCard; use JeroenDesloovere\VCard\VCard;
use Auth; use Auth;
@ -479,25 +480,21 @@ class UserController extends Controller
} }
//Download Vcard //Download Vcard
public function vcard(Request $request) public function vcard(request $request)
{ {
$linkId = $request->id; $linkId = $request->id;
$link = Link::findOrFail($linkId); // find the link with the given ID or throw an exception
$buttonValue = $link->button_value;
$content = $link->content;
Link::where('id', $linkId)->increment('click_number', 1); // Find the link with the specified ID
$link = Link::findOrFail($linkId);
// build the vCard string // Set the response headers to indicate that a VCard file should be downloaded
$vCard = "BEGIN:VCARD\r\nVERSION:3.0\r\n"; $headers = [
$vCard .= "FN:$buttonValue\r\n"; 'Content-Type' => 'text/vcard',
$vCard .= "NOTE:$content\r\n"; 'Content-Disposition' => 'attachment; filename="vcard.vcf"',
$vCard .= "END:VCARD\r\n"; ];
// return the vCard content as a downloadable response // Return the link's content as a downloadable file
return response($vCard) return Response::make($link->link, 200, $headers);
->header('Content-Type', 'text/vcard')
->header('Content-Disposition', 'attachment; filename=vcard.vcf');
} }
//Show link, click number, up link in links page //Show link, click number, up link in links page