K
K
KBBS2020-12-11 19:51:42
Software design
KBBS, 2020-12-11 19:51:42

What kind of data to transfer to the service layer of the application?

Greetings!
We develop API on Laravel with colleagues.
Given:

  1. All validation via FormRequests
  2. The main business logic is in the service layer
  3. Services must receive data from the request

Roughly speaking, in the controller method, we simply call the corresponding service method. And all the logic is already there.
But there was a holivar on the topic: what exactly needs to be transferred to the service.
Transfer the request instance, and the service should already be engaged in extracting data from the request?
Or should the data from the request be retrieved in the controller and passed to the service method?

Let's say if we want to login a user using email and password, which one would be more correct? Just for example.
In controller:
$result = $this->userService->login($request); // Первый вариант.

$credentials = $request->only(['email', 'password']);
$result = $this->userService->login($credentials); // Второй вариант.

Most likely, there is no unambiguously correct answer to this question.
Just interested in the opinion of the public. How do you do, and how do you think is more correct. And why.

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-12-11
@KBBS

As soon as you and your colleagues try to use your service in the console command, where, although there is a request, there is no sense in it, then the question “what to send to the service - a request or something else” will disappear by itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question