Skip to content

Commit

Permalink
Merge pull request #17 from ampeco/master
Browse files Browse the repository at this point in the history
  • Loading branch information
reindert-vetter authored Aug 11, 2022
2 parents af2691f + 5e985cf commit 2b54bee
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Middleware/Version/Bind.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

use Closure;
use Illuminate\Http\Request;
use Illuminate\Container\Container;
use ReindertVetter\ApiVersionControl\Concerns\CacheableVersion;
use Illuminate\Http\Resources\Json\JsonResource;

class Bind
{
Expand All @@ -22,7 +24,13 @@ public function __construct($abstract, $concrete)

public function handle(Request $request, Closure $next)
{
app()->bind($this->abstract, $this->concrete);
if (is_subclass_of($this->concrete, JsonResource::class)){
app()->bind($this->abstract, function(Container $container){
return new $this->concrete(new \stdClass);
});
} else {
app()->bind($this->abstract, $this->concrete);
}

return $next($request);
}
Expand Down

0 comments on commit 2b54bee

Please sign in to comment.