YorCreative / Laravel-UrlShortener

A Laravel URL Shortener package that provides URL redirects with optionally protected URL password, Hidden UTM parameter tracing, URL expiration, open limits before expiration, ability to set feature activation dates, and click tracking out of the box for your Laravel applications.
MIT License
100 stars 15 forks source link

Ability for multiple domains #15

Open KnightAR opened 1 year ago

KnightAR commented 1 year ago

Summary:

Provide ability to build short URLs that has multiple domains/prefixes

Use cases:

I develop a SAS project that we would like to incorporate this package into. However, Since we have multiple domains for different things we'd like to be able to specify which domain to use. For example, we want to send a short link for a specific feature set that is under one domain or subdomain but also want to provide shortlinks for another domain under the same sourecode and configuration setup. The current code base as it stands won't allow me to create these shortlinks easily without some string replacement which I would prefer to avoid.

Expectations:

Thank you for this wonderful package and looking forward to your response on this enhancement.

yordadev commented 1 year ago

Hey @KnightAR 👋🏼

First of all, thank you for such a nicely formatted issue & the kind words. 🙏🏼 🍻

This is a great feature request and I'm going to try and find time in the next ~two weeks to knock this out. Things are crazy right now since I am starting my last week of my masters, lots of hustling and bustling to get things done for my final submission.

If this is something you or anyone else is interesting in contributing towards the package before I get to it. The money maker for this change is ultimately here. We'll want to add a new Builder Option into the actual builder and place it in here. You'll want to implement it similar to how withPassword(string $password) is setup, except with withCustomBase(string $base_url) or something similar. It will allow the package to pivot the base domain here when building the short url.

UrlService::shorten('something-extremely-long.com/even/longer?ref=with&some=thingelselonger')
->withCustomBase('somethingcool.com')
->build(); 

// somethingcool.com/prefix/identifier
yordadev commented 3 months ago

This is going in the v3 release that I've been actively working. I am hoping to get the release PR up next week or so for feedback.

UrlService::shorten('something-extremely-long.com/even/longer?ref=with&some=thingelselonger')
->withDomain('somethingcool.com')
->build(); 

// somethingcool.com/prefix/identifier
KnightAR commented 3 months ago

Hi @yordadev,

Thanks for getting to this. There are a few things I implemented in my source code that makes the code work smoothly. Please consider the following:

Add an alternate branding config key thay allows you to switch between brandings: allow for the default branding to be the defaults and have the alternate override depending on your branding you want. Ie. Different domain, images, password settings, etc.

I hacked it all in my repo. I currently have 5 different domains with different brandings, host and prefix variations without having to manually set a custom host. This way yoy can just loop though and create the routes based off of them. Right now I'm manually setting the route.

I think this will cover my needs and give more flexibility to the overall package for other users needs.

Additional optional suggestion would be allowing the user to make a shortened url that can be resticted to that branding only, returning a 404 if its attempted on another branding.

Let me know what you think