Download the PHP package laracrafts/laravel-geo-routes without Composer

On this page you can find all versions of the php package laracrafts/laravel-geo-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-geo-routes

GeoLocation Restricted Routes For Laravel

Requirements

Installation

Navigate to your project's root folder via terminal or command prompt and execute the following command:

Note: If you are using package discovery, you can skip the registration of the service provider and the alias as they do register themselves automatically, but don't forget to publish the configuration as described below.

Open your config/app.php file and add this entry to the providers array

While still in the same folder, execute this command in your terminal:

Usage

Regular Routes

To get started real quick, the allowFrom and denyFrom methods allow you to restrict access to routes depending on GeoLocations

What the above example does, is allowing access to the /home route only from the United States and the United Kingdom.

Alternatively we can do something like the following:

By default, all other countries will receive an HTTP 401 Unauthorized Error, to change this behavior you can use a callback as described in the callbacks section.

So in the second example we are going to deny access only from specific locations, for instance: Canada, Germany and France

Alternatively:

Note: This package uses ISO Alpha-2 country codes.

Note: This package uses stevebauman's location package, please refer to it's official documentation for a detailed guide on how to configure it correctly.

Route Groups

Besides allowing you to control access to regular routes, the laravel-geo-routes package also allows you to define route groups and do the same trick with them.

Please consider the following example:

Note: As you may have noticed, we are using the geo method instead of the default group method which will behave the same way the group method does, accepting an array of attributes for the first argument and a routes closure for the second one.

Note: Attributes methods can only be used after calling the geo method so instead of Route::name('english.')->geo(...); you have to write Route::geo(...)->name('english.');

Note: Unless a rule is applied using the from, allow, deny, allowFrom or denyFrom methods the route group will not be defined.

Manual configuration

Under the hood, the allowFrom and the denyFrom methods set the geo attribute on the routes which is an array containing the following parameters:

Therefore, if you are more into verbosity, you can define your GeoRoutes in the following way:

Your GeoGroups may also be defined manually as in the following example:

Callbacks

As mentioned earlier, the default behavior for unauthorized users is an HTTP 401 Unauthorized Error response, but you are still able to change this behavior by using callbacks.

To use a callback you have to simply add ->orCallback() to the end of the GeoRoute constraint, like so:

Note: You can also mixin with native router methods

Laravel-geo-routes has some useful built-in callbacks, we are going to list them below along with their use cases.

The orNotFound callback will result in an HTTP 404 Not Found response for unauthorized visitors.

This callback accepts one required argument which has to be a valid route name. Thanks to this callback, you'll be able to redirect unauthorized visitors to a route of your choice.

Now your callbacks are ready, and you can start using them like so:

Notice that we have added the or prefix and converted the callback name to studly case (e.g. myCallback was converted to orMyCallback), be sure not to forget this note as it is very important for your callback to work.

You may also load these callbacks using the parseCallbacks method of the CallbackRegistrar.

Example:

2. Using an array of callbacks

The loadCallbacks method allows you to load an associative array of callbacks.

Example:

3. Using the callback method

The callback method allows you to add a single custom callback, accepting a name and a callable.

Example:

Artisan Command

We have tweaked the route:list command and added new options in order to make retrieving the geo-constraint information easier. Below you will find the list of new options along with their usage examples.

Option Value Description Usage
--geo|-g None Show the routes geo specifications php artisan route:list --geo
--geo-only None Display GeoRoutes only php artisan route:list --geo-only
--country String (ISO Alpha-2 Country Code) Display only the routes that have a given country php artisan route:list --country=[COUNTRY]
--strategy String (allow|deny) Display only the routes that have a given strategy php artisan route:list --strategy=[STRATEGY]

Contribution

All contributions are welcomed for this project, please refer to the CONTRIBUTING.md file for more information about contribution guidelines.

License

Copyright (c) 2019 LaraCrafts.

This product is licensed under the MIT license, please refer to the License file for more information.


All versions of laravel-geo-routes with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
laravel/framework Version ^5.5,<5.9
stevebauman/location Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package laracrafts/laravel-geo-routes contains the following files

Loading the files please wait ....