koel/app/Http/Controllers/API/Search/SongSearchController.php
2022-07-29 09:04:44 +02:00

24 lines
586 B
PHP

<?php
namespace App\Http\Controllers\API\Search;
use App\Http\Controllers\Controller;
use App\Services\SearchService;
use Illuminate\Http\Request;
use InvalidArgumentException;
class SongSearchController extends Controller
{
public function __construct(private SearchService $searchService)
{
}
public function index(Request $request)
{
throw_unless((bool) $request->get('q'), new InvalidArgumentException('A search query is required.'));
return [
'songs' => $this->searchService->searchSongs($request->get('q')),
];
}
}