Download the PHP package roddy/url-shortener without Composer
On this page you can find all versions of the php package roddy/url-shortener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download roddy/url-shortener
More information about roddy/url-shortener
Files in roddy/url-shortener
Package url-shortener
Short Description A Laravel package for creating shortened URLs with QrCode for your web apps.
License MIT
Homepage https://github.com/Freddywhest/url-shortener
Informations about the package url-shortener
Table of Contents
- Overview
- Installation
- Requirements
- Install the Package
- Publish the Config and Migrations
- Migrate the Database
- Usage
- Generating Shortened URLs
- Quick Start
- Domain for the Shortened URL
- Custom Keys
- Set User id
- Schedule when the url can be access
- Generate a QrCode Image for Short Url
- Generate a QrCode Svg for Short Url
- Rules for Generating Shortened URLs
- Retrieving Url
- Find by Id
- Find by URL Key
- Find by Original URL
- Find Where
- Get all URLs
- Deleteing Url
- Delete by id
- Delete by URL Key
- Delete by Original URL
- Delete Where
- Get Instance of Model
- urlShortenerDB
- Generating Shortened URLs
- Security
- Credits
- License
Overview
A Laravel package that can be used for adding shortened URLs to your existing web app.
Installation
Quick note: You must have a basic understanding of the use of the artisan command and composer for installing laravel package.
Requirements
The package has been developed and tested to work with the following minimum requirements:
- PHP >= 8.0
- Laravel >= 8.0
Install the Package
You can install the package via Composer:
Publish the Config and Migrations
You can then publish the package's config file and database migrations by using the following command:
Migrate the Database
This package contains a migration that add a new table to the database: . To run this migration, simply run the following command:
Usage
Generating Shortened URLs
Start
There are two(2) ways to start using url-shortener
- Generate Shortened Url and Store it into the Database
-
Generate Shortened Url Without Storing it into the Database
Generate Shortened Url and Store it into the Database
To store a generated shortened url, you need to add the method.
For example:
Generate Shortened Url Without Storing it into the Database
To not store a generated shortened url, you do not need to add the method.
For example:
Domain for the Shortened URL
By default the domain for the shortened url will be the current domain of the website. For example if the domain for your website is http://mywebsite.com, your shortened url will use http://mywebsite.com as the domain. You can change it by setting the in to the domain you want.
Custom Keys
By default, the shortened URL that is generated will contain a random url key. The url key will be of the length that you define in the config files (defaults to 7 characters). Config file can be found in . Example: if a URL is , the key is .
You may wish to define a custom url key for your shortened url rather than generating a random key. You can do this by using the method.
Examples:
-
This example will store the generated shortened url with the custom key into the database;
- This example will generated a shortened url with the custom key without storing it into the database;
User id
Urlshortener allows you to add a user id to the generated short url to indicate the user that generated it. By default it is , you can add a user id by using the method.
Examples:
-
This example will store the generated shortened url with the user id into the database;
- This example will generated a shortened url with the user id without storing it into the database;
-
Schedule when the url can be access
By default, all short URLs that you generate can be access on the day you generated it. However, you may set a date for accessing your URLs when you're generating them. You can do this by using the method. The method accepts number of days as the parameter and it must be .
Exapmles:
-
This example will store the generated shortened url with the schedule date into the database;
- This example will generated a shortened url with the schedule date without storing it into the database;
Generate a QrCode Image for Short Url
You can generate a QrCode image for your short url by using the method.
Note: This method generate an image url for the QrCode, example of the image url data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKUAAAClCAIAAACyS
.
Note: You can not use and at the same time, you have to use only one of them.
Examples of usage:
-
This example will store the generated shortened url with the generated QrCode Image into the database;
- This example will generated a shortened url with the generated QrCode Image without storing it into the database;
Generate a QrCode Svg for Short Url
You can generate a QrCode svg for your short url by using the method. Note: You can not use and at the same time, you have to use only one of them.
Examples of usage:
-
This example will store the generated shortened url with the generated QrCode Svg into the database;
- This example will generated a shortened url with the generated QrCode Svg without storing it into the database;
Rules for Generating Shortened URLs
- You can not use and at the same time, you have to use only one of them.
- The method should always be the last method.
- The method accepts only int/number as the days parameter.
Retrieving Url
Find by Id
To find the ShortURL model that corresponds to a given shortened URL id, you can use the method.
For example, to find the ShortURL model of a shortened URL that has the id , you could use the following:
Find by URL Key
To find the ShortURL model that corresponds to a given shortened URL key, you can use the method.
For example, to find the ShortURL model of a shortened URL that has the key , you could use the following:
Find by Original URL
To find the ShortURL model that corresponds to a given shortened URL original Url, you can use the method.
For example, to find all of the ShortURL models of shortened URLs with original url of , you could use the following:
Find Where
To find the ShortURL model that corresponds to a given custom query or filter, you can use the method.
For example, to find all shortened url you could use the following:
Note: the method takes 3 parameters, which are , you can set the parameter to if you don't want to provide an . Example:
Get all URLs
To get all Shortened URL, you can use the method.
Example:
Deleteing Url
Note: All the delete methods returns an array.
Delete by id
To delete the ShortURL model that corresponds to a given shortened URL id, you can use the method.
For example, to delete the ShortURL model of a shortened URL that has the id , you could use the following:
Delete by URL Key
To delete the ShortURL model that corresponds to a given shortened URL key, you can use the method.
For example, to delete the ShortURL model of a shortened URL that has the key , you could use the following:
Delete by Original URL
To delete the ShortURL model that corresponds to a given shortened URL original url, you can use the method.
For example, to delete the ShortURL model of a shortened URL that has the original url , you could use the following:
Delete Where
To delete the ShortURL model that corresponds to a given custom query or filter, you can use the method.
For example, to delete all shortened url you could use the following:
Note: the method takes 3 parameters, which are , you can set the parameter to if you don't want to provide an . Example:
Get Instance of Model
urlShortenerDB
urlShortenerDB returns the urlShortener Model which allows you to use all the methods provided by Laravel. To see the Eloquent methods click https://laravel.com/docs/10.x/eloquent.
Example of Usage:
Security
If you find any security related issues, please contact me directly at [email protected] to report it.
Contribution
If you wish to make any changes or improvements to the package, feel free to make a pull request.
Credits
- Alfred Nti
- Chillerlan (QrCode Generator)
- All Contributors
License
The MIT License (MIT). Please see License File for more information.