Created
May 26, 2023 11:29
-
-
Save filipfilipovich/17e4e4d4d861577b0c86fb6a6f296666 to your computer and use it in GitHub Desktop.
GetBookByIsbnController class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Repositories\BookRepository; | |
use Illuminate\Http\Request; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
class GetBookByIsbnController extends Controller | |
{ | |
public function __construct(private readonly BookRepository $bookRepository) | |
{ | |
} | |
public function __invoke(Request $request): JsonResponse | |
{ | |
$bookFound = $this->bookRepository->findBy([ | |
$parameter = 'isbn' => $request->route()?->parameter($parameter) | |
]); | |
return new JsonResponse($bookFound->first()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment