First i put business logic like for example upload a profile image to user model in the user model. Then i noticed that i need it in my team model, too.
Now i created a ServiceClass "UploadFileService" for this business logic. Is this the right place?
My Models are cleaner now and the business logic is separated. I guess its ok so.
Hello @RomainLanz ,
but why i need an extra ServiceProvider? What is the benefit here? I could also create a normal Class "FileUpload". I dont understand the benefits of ServiceProviders.
But I wouldn't add the "Service" extension, personally. There's no need for it. Just name the class what it does. "UploadsFile", if that's what you want.
Service providers is for configuring and providing services, if needed. Lets say your UploadFile service needs to be injected some extra classes before being used (filesystem disk class for example), this configuration takes place in a service provider. If your service is a bare class that can be used like this, no need for service provider.
@RomainLanz Erm, that’s exactly where logic is supposed to go in an MVC-like application. You’re right in that it doesn’t belong in a controller, and it definitely doesn’t belong in a view.
Service classes are great for encapsulating logic that may be used in more than one model.