TubeSum

Service vs Action Classes in Laravel — Full Breakdown & Transcript

Service vs Action Classes in Laravel: What's the Difference?

0h 00m video Published Feb 11, 2025 Transcribed Aug 14, 2026 L Laravel Daily
Beginner 1 min read For: Laravel developers looking to understand common design patterns for organizing business logic.
AI Trust Score 80/100
✅ Highly Legit

"The title accurately reflects the content, providing a clear and concise explanation of the difference."

AI Summary

The video explains the difference between service and action classes in Laravel. It provides examples of how each is used in controllers and queued jobs, and emphasizes that both are flexible PHP classes.

[00:00]
Service Class Definition

A service class groups methods around a specific Eloquent model or topic, with all public methods callable individually.

[00:15]
Service Usage in Queued Jobs

Services can be used in queued jobs by creating a new object and calling methods like getBrowser(), getOS(), getDevice().

[00:30]
Service Usage in Controllers

In controllers, services are instantiated to call a single method, like getting the operating system.

[00:30]
Action Class Definition

Action classes typically have one method like handle() or invoke(), but can have more methods.

[00:46]
Action Usage in Controllers

Action classes are used in controllers by creating a new object and calling the handle() method with parameters.

[00:46]
Flexibility and Conclusion

Both service and action classes are just PHP classes, so you can structure them however you want.

Study Flashcards (3)

What is a service class in Laravel?

easy Click to reveal answer

A service class groups methods around a specific Eloquent model or topic, with all public methods callable individually.

What is an action class in Laravel?

easy Click to reveal answer

An action class typically has one method like handle() or invoke() to perform a single use case.

00:30

What is the key difference between service and action classes?

medium Click to reveal answer

Services are broader, grouping related operations, while actions focus on a single task.

00:46

💡 Key Takeaways

💡

Service Class Definition

Clarifies that services group methods around a model or topic, not necessarily tied to a single model.

💡

Action Class Definition

Highlights that actions typically have a single method, but can have more, offering flexibility.

00:30
⚖️

Flexibility in Structure

Emphasizes that both are just PHP classes, giving developers freedom to structure them as needed.

00:46

[00:00] Service and action classes in Laravel. Typically service is a group of methods around the same eloquent model, but not necessarily, it could be one topic like user agent. And as you can see, all methods here are public, which means they can be called individually, or at the end there is a

[00:15] method to call multiple methods with one public method. And how that service is used, for example, in a queued job we create a new class object and then get browser, get OS, get device. Another example in controller, we also create a new object of that service, but in this case just to get the

[00:30] operating system. And here's an example of action class from another project. Typically action class has one method like handle or invoke, but no one is restricting you from creating more methods inside of the same action class like this. And this is how it is used in the controller, we create

[00:46] a new object of action, and then we just call one method handle with parameters. So I hope you see the difference between service and actions, but at the end of the day they are both PHP classes, and you can structure them however you want.

More from Laravel Daily

View all

⚡ Saved you 0h 00m reading this? Transcribe any YouTube video for free — no signup needed.