ldc-qrcollector-back/app/Http/Controllers/Api/BrandController.php

61 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2023-03-24 16:09:27 +00:00
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\BrandCollection;
use App\Http\Resources\BrandResource;
use App\Http\Resources\UrlCollection;
use App\Models\Brand;
use App\Models\Service;
2023-03-24 16:09:27 +00:00
class BrandController extends Controller
{
/**
* Returns a listing of the brands.
*
2026-02-12 16:09:21 +01:00
* @return \App\Http\Resources\BrandCollection
2023-03-24 16:09:27 +00:00
*/
public function index()
{
2023-03-24 16:16:02 +00:00
return new BrandCollection(Brand::paginate(25));
2023-03-24 16:09:27 +00:00
}
/**
* Returns the specified brand.
*
* @param \Illuminate\Http\Request $request
* @param Brand $brand
2026-02-12 16:09:21 +01:00
* @return \App\Http\Resources\BrandResource
*
* @throws \Exception If the brand isn't the brand associated to the service.
2023-03-24 16:09:27 +00:00
*/
public function show(\Illuminate\Http\Request $request, Brand $brand)
2023-03-24 16:09:27 +00:00
{
$service = Service::query()->where('bearer_token', $request->bearer_token)->firstOrFail();
if ($brand != $service->brand) {
throw new \Exception('Invalid brand.');
};
2023-03-24 16:09:27 +00:00
return new BrandResource($brand);
}
/**
* Returns the urls for a given brand.
*
* @param \Illuminate\Http\Request $request
* @param Brand $brand
2026-02-12 16:09:21 +01:00
* @return \App\Http\Resources\UrlCollection
*
* @throws \Exception If the brand isn't the brand associated to the service.
2023-03-24 16:09:27 +00:00
*/
public function getUrls(\Illuminate\Http\Request $request, Brand $brand)
2023-03-24 16:09:27 +00:00
{
$service = Service::query()->where('bearer_token', $request->bearer_token)->firstOrFail();
if ($brand != $service->brand) {
throw new \Exception('Invalid brand.');
};
2023-03-24 16:09:27 +00:00
return new UrlCollection($brand->urls);
}
}