Files
animethemes-server/app/Actions/Models/BackfillAction.php
T
paranarimasu 27778857b1 Request action composition (#516)
* refactor(api): prefer composition to strict inheritance for API queries, requests & actions

* style: fix StyleCI findigns
2023-02-16 23:30:57 -06:00

59 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Actions\Models;
use App\Actions\ActionResult;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;
/**
* Class BackfillAction.
*
* @template TModel of \App\Models\BaseModel
*/
abstract class BackfillAction
{
/**
* Create a new action instance.
*
* @param TModel $model
*/
public function __construct(protected BaseModel $model)
{
}
/**
* Handle action.
*
* @return ActionResult
*/
abstract public function handle(): ActionResult;
/**
* Get the model the action is handling.
*
* @return TModel
*/
abstract protected function getModel(): BaseModel;
/**
* Get the relation to resources.
*
* @return Relation
*/
abstract protected function relation(): Relation;
/**
* Get the human-friendly label for the underlying model.
*
* @return string
*/
protected function label(): string
{
return Str::headline(class_basename($this->getModel()));
}
}