Package for Shortening URL and Expanding URL with Google. This is a great combination if you plan to send Links in your Text Messages fired from your Application.
Via Composer
$ composer require tzsk/shorten-url
First add the Service Provider and Facade in your app config file.
'providers' => [
...
Tzsk\ShortenUrl\Provider\ShortenUrlServiceProvider::class,
...
]
...
'aliases' => [
...
'GoogleUrl' => Tzsk\ShortenUrl\Facade\GoogleUrl::class,
...
]
After that run vendor:publish
with flag config
:
$ php artisan vendor:publish --tag=config
Once you do that you will have a new file in your config folder.
config/url.php
There is only one criteria. Google API key for Shortening URL. Just login with google account and go to [https://console.developers.google.com]
Now create a new Application there. And Enable API
for URL Shortening.
And generate API Key
to use in Credentials
section.
# Use Class Path at the top of the File.
use Tzsk\ShortenUrl\Facade\GoogleUrl;
# Inside your Controller Method for Shortening.
$short = GoogleUrl::shorten("LONG URL"); # Returns String.
# OR...
$short_data = GoogleUrl::extended()->shorten("LONG URL");
/**
* For extended it will give the full response that google provides.
*/
# Inside your Controller Method for Expanding.
$long = GoogleUrl::expand("SHORT URL"); # Returns String.
# OR...
$long_data = GoogleUrl::extended()->expand("SHORT URL");
/**
* For extended it will give the full response that google provides.
*/
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email mailtokmahmed@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.