1. Go to this page and download the library: Download j3ns3n/laravel-linkly library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
j3ns3n / laravel-linkly example snippets
use J3ns3n\LaravelLinkly\Facades\Linkly;
// Create a new short link
$link = Linkly::createLink([
'url' => 'https://example.com/very-long-url',
'name' => 'My Example Link',
]);
echo $link->getShortUrl();
echo $link->getId();
use J3ns3n\LaravelLinkly\Client\LinklyClient;
class LinkController extends Controller
{
public function __construct(protected LinklyClient $linkly)
{
}
public function store(Request $request)
{
$link = $this->linkly->createLink([
'url' => $request->input('url'),
'name' => $request->input('name'),
]);
return response()->json($link);
}
}
use J3ns3n\LaravelLinkly\Facades\Linkly;
$link = Linkly::build('https://example.com')
->name('My Example Link')
->slug('my-slug')
->domain('custom.domain')
->cloaking()
->blockBots()
->forwardParams(false)
->webhook('https://webhook.site/abc')
->utm('newsletter', 'email', 'launch')
->openGraph('OG Title', 'OG Desc', 'https://img.com/og.png')
->expires('2025-12-31T23:59:59Z', 'https://expired.com')
->rules(['matches' => 'US', 'percentage' => 50, 'url' => 'https://us.com', 'what' => 'geo'])
->create();
// The returned $link is an instance of J3ns3n\LaravelLinkly\Resources\Link
// Create a link
$link = Linkly::createLink([
'url' => 'https://example.com',
'name' => 'Example',
]);
// Get a link by ID
$link = Linkly::getLink($link->getId());
// List all links
$links = Linkly::listLinks();
foreach ($links as $link) {
echo $link->getShortUrl();
}
// Update a link
$link = Linkly::updateLink($link->getId(), [
'name' => 'Updated Name',
]);
// Delete a link
Linkly::deleteLink($link->getId());
$link = Linkly::getLink(LINK_ID);
// Access properties
echo $link->getId();
echo $link->getShortUrl();
echo $link->getOriginalUrl();
// Update the link
$link = $link->update([
'name' => 'Updated Name',
// ...other fields...
]);
// Delete the link
$deleted = $link->delete();
// Convert to array
$array = $link->toArray();
// Convert to JSON
$json = json_encode($link);