Laravel: Service Layer with DTOs and Validators

Luís Nóbrega
7 min readApr 30, 2020

An example of how to have a Service Layer with DTOs using Laravel Validator.

Photo by Markus Spiske on Unsplash

What is a Service Layer?

Photo by Nikolai Justesen on Unsplash

A Service Layer is a design pattern. Design patterns are common solutions in software design.

This one abstracts our domain logic. It delegates the application logic to common services.

It is a way of moving to skinny controllers, helping us not to repeat code, avoiding to have everything in the controller.

Need to return JSON and HTML from the controllers? Ideas on how this could be acomplished.

This layer is usually placed between controllers and repositories, and it is common to have the concerns of file system access, database access, or email sending.

If you would like to see an example of this service layer implementation, check out this article using Unsplash API with a Service Layer and DTOs.

What are DTOs?

--

--

Luís Nóbrega
Luís Nóbrega

Written by Luís Nóbrega

Web Developer at 25friday. Likes to travel, write and being a father.