60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?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;
|
|
|
|
class BrandController extends Controller
|
|
{
|
|
/**
|
|
* Returns a listing of the brands.
|
|
*
|
|
* @return \App\Http\Resources\BrandCollection
|
|
*/
|
|
public function index()
|
|
{
|
|
return new BrandCollection(Brand::paginate(25));
|
|
}
|
|
|
|
/**
|
|
* Returns the specified brand.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param Brand $brand
|
|
* @return \App\Http\Resources\BrandResource
|
|
*
|
|
* @throws \Exception If the brand isn't the brand associated to the service.
|
|
*/
|
|
public function show(\Illuminate\Http\Request $request, Brand $brand)
|
|
{
|
|
$service = Service::query()->where('bearer_token', $request->bearer_token)->firstOrFail();
|
|
if ($brand != $service->brand) {
|
|
throw new \Exception('Invalid brand.');
|
|
};
|
|
|
|
return new BrandResource($brand);
|
|
}
|
|
|
|
/**
|
|
* Returns the urls for a given brand.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param Brand $brand
|
|
* @return \App\Http\Resources\UrlCollection
|
|
*
|
|
* @throws \Exception If the brand isn't the brand associated to the service.
|
|
*/
|
|
public function getUrls(\Illuminate\Http\Request $request, Brand $brand)
|
|
{
|
|
$service = Service::query()->where('bearer_token', $request->bearer_token)->firstOrFail();
|
|
if ($brand != $service->brand) {
|
|
throw new \Exception('Invalid brand.');
|
|
};
|
|
return new UrlCollection($brand->urls);
|
|
}
|
|
}
|