I have this type of situation, I have controllers , for example AuthController with functions register and login, I have service called AuthService, here I implement functions where I have all type of logic and communication with database. all I do in controller is $auth_service->register($request) and then Auth service does everything, returns response object and then in controller I return this object as Json. so i have no eloquent functions in controller, no business logic just 3-4 line of code. Is that a good practice? for example if I have need only Modell:all() function in controller I have to use service function even for that little piece of code, otherwise I will have structure where I sometimes use services and sometimes not. Also when I inject service class in controller, I also inject all useful models (sometimes other services) in this service too, if in one controller sometimes I use service and sometimes work with models directly, then turns out that I inject model in service and in controller (injecting same model two times). so should I continue doing like that and use service fore each controllers each function? I mean which way will be better and why?
this is my auth controller's register function:
protected $auth_service;
public function __construct(AuthService $auth_service){
$this->auth_service = $auth_service;
}
public function registerUser(UserRegisterRequest $request){
$registerUser = $this->auth_service->registerUser($request);
return response()->json($registerUser, 200);
}
and this is language controller:
protected $language;
public function __construct(Language $language){
$this->language = $language;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$languages = $this->language->getAllLanguage();
return response()->json(['data'=>$languages], 200);
}
in second example I use model's function directly from controller, but if I choose that first example is better, I should make language service and use it in language controller's index method even though it's quite simple and doesn't need any simplification, so what do you think?