Skip to content

Commit 23e4fbc

Browse files
committed
[Feature] Add Laravel 5.4 support
Initial support for Laravel 5.4 - requires additional testing
1 parent b675f98 commit 23e4fbc

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/Schema/CreatesEloquentIdentities.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ protected function createBelongsToIdentity(Model $model, $relationshipKey)
6060
}
6161

6262
$related = $relation->getRelated()->replicate();
63-
$related->{$relation->getOtherKey()} = $id;
63+
64+
/** Laravel 5.4 */
65+
if (method_exists($relation, 'getOwnerKey')) {
66+
$related->{$relation->getOwnerKey()} = $id;
67+
} /** Laravel 5.1|5.2|5.3 */
68+
else {
69+
$related->{$relation->getOtherKey()} = $id;
70+
}
6471

6572
return $related;
6673
}

src/ServiceProvider.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,15 @@ protected function bootPublishing()
158158
*/
159159
protected function bootMiddleware(Router $router)
160160
{
161-
$router->middleware('json-api', BootJsonApi::class);
162-
$router->middleware('json-api.request', HandleRequest::class);
161+
/** Laravel 5.4 */
162+
if (method_exists($router, 'aliasMiddleware')) {
163+
$router->aliasMiddleware('json-api', BootJsonApi::class);
164+
$router->aliasMiddleware('json-api.request', HandleRequest::class);
165+
} /** Laravel 5.1|5.2|5.3 */
166+
else {
167+
$router->middleware('json-api', BootJsonApi::class);
168+
$router->middleware('json-api.request', HandleRequest::class);
169+
}
163170
}
164171

165172
/**
@@ -282,29 +289,32 @@ protected function bindErrorRepository()
282289
{
283290
$this->app->singleton(ReplacerInterface::class, Replacer::class);
284291

285-
$this->app->singleton(['json-api.errors' => ErrorRepositoryInterface::class], function () {
292+
$this->app->singleton(ErrorRepositoryInterface::class, function () {
286293
/** @var ReplacerInterface $replacer */
287294
$replacer = $this->app->make(ReplacerInterface::class);
288295
$repository = new ErrorRepository($replacer);
289296
$repository->configure($this->getErrorConfig());
290297
return $repository;
291298
});
299+
$this->app->alias(ErrorRepositoryInterface::class, 'json-api.errors');
292300
}
293301

294302
/**
295303
* Bind the exception parser into the service container.
296304
*/
297305
protected function bindExceptionParser()
298306
{
299-
$this->app->singleton(['json-api.exceptions' => ExceptionParserInterface::class], ExceptionParser::class);
307+
$this->app->singleton(ExceptionParserInterface::class, ExceptionParser::class);
308+
$this->app->alias(ExceptionParserInterface::class, 'json-api.exceptions');
300309
}
301310

302311
/**
303312
* Bind the store into the service container.
304313
*/
305314
protected function bindStore()
306315
{
307-
$this->app->singleton(['json-api.store' => StoreInterface::class], Store::class);
316+
$this->app->singleton(StoreInterface::class, Store::class);
317+
$this->app->alias(StoreInterface::class, 'json-api.store');
308318
}
309319

310320
/**
@@ -341,7 +351,8 @@ protected function bindStoreAdapters()
341351
*/
342352
protected function bindLinkFactory()
343353
{
344-
$this->app->singleton(['json-api.links' => LinkFactoryInterface::class], LinkFactory::class);
354+
$this->app->singleton(LinkFactoryInterface::class, LinkFactory::class);
355+
$this->app->alias(LinkFactoryInterface::class, 'json-api.links');
345356
}
346357

347358
/**

0 commit comments

Comments
 (0)