In my opinion, just use laravel conventions and MVC.
I suggest a search of past discussions on the repository pattern by me and others on the forum.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I’m working with a base repository in Laravel that handles generic operations like create, find, and update.
The structure looks like this:
abstract class BaseRepository {
protected Model $model;
public function __construct(Model $model) {
$this->model = $model;
}
public function create(array $data): Model {
return $this->model->create($data);
}
}
Then I extend it like this:
class CategoryRepository extends BaseRepository {
public function __construct(Category $model) {
parent::__construct($model);
}
}
In my service, I do something like:
public function createCategory(array $data): Category
{
return $this->categoryRepository->create($data); // <-- returns Model, not Category
}
My Question: Is there any way to make the base create() method return the actual model type like Category, not just Model?
I don't want to have to rewrite the same create() method in every child repository just to fix the return type.
Is this possible in PHP? Or is there some pattern or trick people use to solve this?
Thanks in advance!
Please or to participate in this conversation.