Download the PHP package soulcodex/model-keyable without Composer

On this page you can find all versions of the php package soulcodex/model-keyable. 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 model-keyable

Laravel Keyable

Keyable is a package that allows you to add API Keys to any model. This allows you to associate incoming requests with their respective models. You can also use Policies to authorize requests.

Installation

Require the package in your and update your dependencies:

Publish the migration and config files:

Run the migration:

Usage

Add the trait to your model(s):

Add the middleware to the function in your file:

The middleware will authenticate API requests, ensuring they contain an API key that is valid.

Accessing keyable models in your controllers

The model associated with the key will be attached to the incoming request as :

Now you can use the keyable model to scope your associated API resources, for example:

Keys Without Models

Sometimes you may not want to attach a model to an API key (if you wanted to have administrative access to your API). By default this functionality is turned off:

UUID support

Before migrate you can config if you prefer use bigint or uuid identifiers. By default use bigint like keyable_id

Making Requests

By default, laravel-keyable uses bearer tokens to authenticate requests. Attach the API key to the header of each request:

You can change where the API key is retrieved from by altering the setting in the keyable.php config file. Supported options are: bearer, header, and parameter.

As it is an array, you can use more than one of these options and combine them.

Need to pass the key as a URL parameter? Set the mode to parameter and the key to the string you'll use in your URL:

Now you can make requests like this:

Authorizing Requests

Laravel offers a great way to perform Authorization on incoming requests using Policies. However, they are limited to authenticated users. We replicate that functionality to let you authorize requests on any incoming model.

To begin, add the AuthorizeKeyableRequest trait to your base Controller.php class:

Next, create the app/Policies/KeyablePolicies folder and create a new policy:

Lastly, register your policies in AuthServiceProvider.php:

In your controller, you can now authorize the request using the policy by calling $this->authorizeKeyable(<ability>, <model>):

Artisan Commands

Generate an API key:

Delete an API key:

Security

If you discover any security related issues, please email [email protected].

License

Released under the MIT license. See LICENSE for more information.


All versions of model-keyable with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^7.4|^8.0
spatie/laravel-package-tools Version ^1.1
illuminate/contracts Version ^7.0|^8.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 soulcodex/model-keyable contains the following files

Loading the files please wait ....