Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

realodix/urlhub

532 stars
2 code files
View realodix/urlhub on GitHub

app/Models/Url.php

Open in GitHub
use Illuminate\Database\Eloquent\Model;
 
class Url extends Model
{
//
protected $casts = [
'user_id' => 'int',
'is_custom' => 'boolean',
];
//
}

app/Services/UrlService.php

Open in GitHub
use App\Models\Url;
 
class UrlService
{
protected $url;
 
protected $keySrvc;
 
public function __construct()
{
$this->url = new Url;
$this->keySrvc = new KeyService;
}
 
//
public function shortenUrl($request, $authId)
{
$key = $request['custom_key'] ?? $this->keySrvc->urlKey($request['long_url']);
 
return Url::create([
'user_id' => $authId,
'long_url' => $request['long_url'],
'meta_title' => $request['long_url'],
'keyword' => $key,
'is_custom' => $request['custom_key'] ? 1 : 0,
'ip' => request()->ip(),
]);
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.