mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-25 08:14:29 +02:00
* refactor(api): prefer composition to strict inheritance for API queries, requests & actions * style: fix StyleCI findigns
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Contracts\Http\Api\InteractsWithSchema;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Class BaseController.
|
|
*/
|
|
abstract class BaseController extends Controller implements InteractsWithSchema
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @param string $model
|
|
* @param string $parameter
|
|
*/
|
|
public function __construct(string $model, string $parameter)
|
|
{
|
|
$this->authorizeResource($model, $parameter);
|
|
$this->middleware('auth:sanctum')->except(['index', 'show']);
|
|
$this->middleware("can:restore,$parameter")->only('restore');
|
|
$this->middleware("can:forceDelete,$parameter")->only('forceDelete');
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
}
|