mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-08 05:33:12 +02:00
* refactor(api): prefer composition to strict inheritance for API queries, requests & actions * style: fix StyleCI findigns
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\Pivot;
|
|
|
|
use App\Contracts\Http\Api\InteractsWithSchema;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Class PivotController.
|
|
*/
|
|
abstract class PivotController extends Controller implements InteractsWithSchema
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @param string $foreignModel
|
|
* @param string $foreignParameter
|
|
* @param string $relatedModel
|
|
* @param string $relatedParameter
|
|
*/
|
|
public function __construct(string $foreignModel, string $foreignParameter, string $relatedModel, string $relatedParameter)
|
|
{
|
|
$this->authorizeResource($foreignModel, $foreignParameter);
|
|
$this->authorizeResource($relatedModel, $relatedParameter);
|
|
$this->middleware('auth:sanctum')->except(['index', 'show']);
|
|
}
|
|
|
|
/**
|
|
* Get the underlying schema.
|
|
*
|
|
* @return Schema
|
|
*/
|
|
public function schema(): Schema
|
|
{
|
|
$schemaClass = Str::of(get_class($this))
|
|
->replace('Controllers\\Api', 'Api\\Schema')
|
|
->replace('Controller', 'Schema')
|
|
->__toString();
|
|
|
|
return new $schemaClass();
|
|
}
|
|
}
|