#A question about how to organize my project

3 messages · Page 1 of 1 (latest)

crisp path
#

Idk if this should be here or not, but Idk where to ask or what to read. There are a ton of opinions online about this.

How should I organize my controllers? Rn I have, something like this.
Controller "UserIndexController" which call a service "UserIndexService" just to get the props to send to the view

        $this->viewService = new UserIndexService();
        return Inertia::render(
            "UserIndex",
            $this->viewService->getViewData()
        );

But, if let's say I need to create (it is more complex than User::create) a user or do something else with it, I have a UserService for it.
It is this a good design? I was reading about actions but Idk how to implement them when I need to get the view data. Is having something like UserIndexGetDataAction a good idea or not? But Idk if it helps me, cuz UserIndexService has two public functions instead of one which I need to call in different places of my app. It is ok to combine both actions and services in my case? Or should I stick with services only?

severe drift
# crisp path Idk if this should be here or not, but Idk where to ask or what to read. There a...

You sound like you’re worrying far too and over-complicating naming. Your services also seem over-engineered. Like, UserIndexGetDataAction? Really?

Services tend to be classes with methods relating to a particular topic. So you’d have a UserService with method methods for things relating to users: fetching users, saving users, deleting users, etc. You wouldn’t create a “service” for every individual thing your app does, as that’s essentially what action classes are (a class that performs one thing).

#

I’d honestly just stick to having a UserController with the resource actions, that uses methods a UserService to do stuff. Instead of creating half a dozen “controllers”, and half a dozen “services”, just to manage users.