Laravel Bitly Url Shortener

Sometimes, you need to shorten URL. Especially when you want to send URLs in SMS or Social Media. We will learn about laravel bitly URL shortener composer package.

# Requirements

# Getting Bitly URL Shortener Access Token

First of all, you need to get a bitly access token. Create a new free account into a bitly. Your dashboard will look like below.

Bitly URL Shortener Dashboard

Click on profile settings and after a click on generic access token.

Bitly Profile Settings
generic access token

Enter your account password and click on generic access token to get your bitly access token.

Get Token

# Installing Bitly Package

Install laravel bitly package using following command

composer require shivella/laravel-bitly

Register the service into the app.php‘s providers array.

/* config > app.php */

'providers' => [    
    Shivella\Bitly\BitlyServiceProvider::class,
]

Similarly, register the facade into aliases array.

/* config > app.php */

'aliases' => [    
     'Bitly' => Shivella\Bitly\Facade\Bitly::class,
]

That’s It! You successfully configured laravel bitly.

# Usage

There are two methods you can use it.

$bitlyUrl = app('bitly')->getUrl('https://www.your-url.com/');
echo $bitlyUrl;

Likewise, you can use it with laravel facade.

/* declare bitly namespace */
use Bitly;
$bitlyUrl = Bitly::getUrl('https://www.google.com/');
echo $bitlyUrl;

Check the shortened URL to your browser. It will automatically redirect to your original URL.

Learn more about Laravel Framework

Previous articleHow To Use Laravel Eloquent One To One Relationship
Next articleHow To Use Laravel Eloquent One To Many Relationship
Welcome to the world of web development, where technology and creativity come together to bring ideas to life. My name is Keyur Gadher, and as a web development blogger, I am here to share my knowledge and experience with you. From front-end web development to back-end programming, I will provide you with valuable tips, tricks, and techniques to help you create beautiful and functional websites that are tailored to your specific needs. Whether you're a beginner or a seasoned pro, I am here to help you take your web development skills to the next level. Join me today and let's start coding!

LEAVE A REPLY

Please enter your comment!
Please enter your name here