From dcaf5e6065b638ef89b6b5c4fbed808cadd70876 Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 26 Sep 2017 12:17:32 +0000 Subject: [PATCH] Laravel 5.5 support + readme fix --- README.md | 22 ++++++++++++---------- src/Providers/ApiGuardServiceProvider.php | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6510894e0..8696ba12e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ApiGuard ======== -[![Latest Stable Version](https://poser.pugx.org/chrisbjr/api-guard/v/stable)](https://packagist.org/packages/chrisbjr/api-guard) [![Total Downloads](https://poser.pugx.org/chrisbjr/api-guard/downloads)](https://packagist.org/packages/chrisbjr/api-guard) +[![Latest Stable Version](https://poser.pugx.org/chrisbjr/api-guard/v/stable)](https://packagist.org/packages/chrisbjr/api-guard) [![Total Downloads](https://poser.pugx.org/chrisbjr/api-guard/downloads)](https://packagist.org/packages/chrisbjr/api-guard) [![Join the chat at https://gitter.im/chrisbjr/api-guard](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/chrisbjr/api-guard?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -10,9 +10,9 @@ A simple way of authenticating your APIs with API keys using Laravel. This packa - philsturgeon's [Fractal](https://github.com/thephpleague/fractal) - maximebeaudoin's [api-response](https://github.com/ellipsesynergie/api-response) -## Laravel 5.3 and 5.4 is finally supported! +## Laravel 5.3, 5.4 and 5.5 is finally supported! -**Laravel 5.3.x to 5.4.x: `~4.*` +**Laravel 5.3.x onwards: `~4.*` **Laravel 5.1.x to 5.2.x: [`~3.*`](https://github.com/chrisbjr/api-guard/blob/3.1/README.md) @@ -46,7 +46,7 @@ Then run the migration: $ php artisan migrate -It will setup two tables - api_keys and api_logs. +It will setup `api_keys` table. ### Generating your first API key @@ -56,19 +56,21 @@ Run the following command to generate an API key: `php artisan api-key:generate` -Generally, the `ApiKey` object is a polymorphic object meaning this can belong to more than one other model. +Generally, the `ApiKey` object is a polymorphic object meaning this can belong to more than one other model. To generate an API key that is linked to another object (a "user", for example), you can do the following: -`php artisan api-key:generate --id=1 --type=App\User` ++`php artisan api-key:generate --id=1 --type="App\User"` To specify that a model can have API keys, you can attach the `Apikeyable` trait to the model: ```php +use Chrisbjr\ApiGuard\Models\Mixins\Apikeyable; + class User extends Model { use Apikeyable; - + ... } @@ -124,7 +126,7 @@ throttling. */ protected $middlewareGroups = [ ... - + 'api' => [ 'throttle:60,1', 'bindings', @@ -139,7 +141,7 @@ this method because in most use cases, this is actually the user. ### Unauthorized Requests Unauthorized requests will get a `401` status response with the following JSON: - + ```json { "error": { @@ -271,7 +273,7 @@ class BooksController extends ApiGuardController public function store(BookStoreRequest $request) { // Request should already be validated - + $book = Book::create($request->all()) return $this->response->withItem($book, new BookTransformer); diff --git a/src/Providers/ApiGuardServiceProvider.php b/src/Providers/ApiGuardServiceProvider.php index 8d8555824..680f61126 100644 --- a/src/Providers/ApiGuardServiceProvider.php +++ b/src/Providers/ApiGuardServiceProvider.php @@ -43,7 +43,7 @@ public function register() private function defineMiddleware($router) { foreach ($this->middlewares as $name => $class) { - if (str_contains(App::VERSION(), "5.4.")) { + if ( version_compare(app()->version(), '5.4.0') >= 0 ) { $router->aliasMiddleware($name, $class); } else { $router->middleware($name, $class);