@rully You don’t seem to be following the principles of Domain-Driven Design properly. I’m not sure what’s going on with that repository name (Domain\Carpool\Repositories\CarpoolRepo\carpoolReimbuseRepository seems far too long and nested in too many levels); and your domain layer should know nothing about the application layer, so you shouldn’t be getting errors about expecting instances of Illuminate\Http\Request classes. Requests are an application layer concern; not a domain-layer concern.
In DDD, repositories are used to fetch data, and services are for domain operations (i.e. actions that will end up creating/updating/deleting entities). So you should have a service that creates a reimburse stub (whatever that entity is). That service should also receive pre-validated data and not a HTTP request instance.
If you want to enforce the data that is passed to the service (which is by no means a bad thing at all), then you can use a DTO (data transfer object). This is a class that can only be instantiated with good data, and then you would pass an instance of this DTO class to your service class method. Your service class can then access the data in the DTO, knowing it’s already been validated and is “good”; your service class will no longer need to do any checking of its own any more. Your application layer will then transform input (HTTP request body, console command arguments/options, etc) into an instance of the relevant DTO, and then pass that DTO to your service class in the domain layer:
public function store(StoreReimburseStubRequest $request)
{
// Convert request data to DTO
$dto = CreateReimburseStubDto::fromRequest($request);
// Pass DTO to service class method and create new entity
$reimburseStub = $this->reimburseStubs->create($dto);
// Return some sort of response to client
}
Your domain layer is now completely isolated from the application layer.