{"repo":"givebutter/laravel-keyable","free":true,"listed":false,"github":"https://github.com/givebutter/laravel-keyable","clone":"git clone https://github.com/givebutter/laravel-keyable.git","description":"Add API keys to your Laravel models.","language":"PHP","stars":189,"topics":["laravel","apis","api-keys","authentication","php","rest"],"license":"MIT","category":"auth-billing-email","readme_excerpt":"Laravel Keyable Laravel 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. Generating API keys You can generate new API keys by calling the createApiKey() method from the Keyable trait. When you do so, it returns an instance of NewApiKey , which is a simple class the contains the actual ApiKey instance that was just created, and also contains the plain text api key, which is the one you should use to authenticate requests. You can also manually create API keys without using the createApiKey from the Keyable trait, in that case, the instance you get back will have a property called plainTextApikey populated with the plain text API key. Keep in mind plainTextApikey will only be populated immediately after creating the key. 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 a","default_branch":null,"files":null,"tree":[],"storefront":"/r/givebutter","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/givebutter/laravel-keyable/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}