Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shivella/laravel-bitly

Laravel package for generating bitly url
https://github.com/shivella/laravel-bitly

bitly laravel laravel-bitly php url-shortener

Last synced: 7 days ago
JSON representation

Laravel package for generating bitly url

Awesome Lists containing this project

README

        

Laravel Bitly Package
=====================

A laravel package for generating Bitly short URLs.

For more information see [Bitly](https://bitly.com/)

[![Build Status](https://github.com/Shivella/laravel-bitly/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/Shivella/laravel-bitly/actions) [![Latest Stable Version](https://poser.pugx.org/shivella/laravel-bitly/v/stable)](https://packagist.org/packages/shivella/laravel-bitly) [![License](https://poser.pugx.org/shivella/laravel-bitly/license)](https://packagist.org/packages/shivella/laravel-bitly) [![Total Downloads](https://poser.pugx.org/shivella/laravel-bitly/downloads)](https://packagist.org/packages/shivella/laravel-bitly)

## Requirements ##

Laravel 5.1 or later

Installation
------------
Installation is a quick 3 step process:

1. Download laravel-bitly using composer
2. Enable the package in app.php
3. Configure your Bitly credentials
4. (Optional) Configure the package facade

### Step 1: Download laravel-bitly using composer

Add shivella/laravel-bitly by running the command:

```
composer require shivella/laravel-bitly
```

### Step 2: Enable the package in app.php

Register the Service in: **config/app.php**

``` php
Shivella\Bitly\BitlyServiceProvider::class,
````

### Step 3: Configure Bitly credentials

```
php artisan vendor:publish --provider="Shivella\Bitly\BitlyServiceProvider"
```

Add this in you **.env** file

```
BITLY_ACCESS_TOKEN=your_secret_bitly_access_token
```

### Step 4 (Optional): Configure the package facade

Register the Bitly Facade in: **config/app.php**

```php
[

'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
// ...
'Bitly' => Shivella\Bitly\Facade\Bitly::class,
],
// ...
];
````

Usage
-----

```php
getUrl('https://www.google.com/'); // http://bit.ly/nHcn3
````

Or if you want to use facade, add this in your class after namespace declaration:

```php
make(Kernel::class)->bootstrap();

// swap Bitly client by a fake
$app->singleton('bitly', function () {
return new BitlyClientFake();
});

return $app;
}
}
```

As an alternative you may use `\Shivella\Bitly\Facade\Bitly::fake()` method to swap regular client by a fake.