A service is typically a PHP class or a collection of PHP classes that you would call from within your application. Below, we will create a class that outputs a message, for simplicity.
namespace App\Services\Message;
class Message
{
/**
* Displays a message to the end-user
*
* @param string $message the message to display
*
* @return string
*/
public function display(string $message): string
{
return $message;
}
}As you can see, this services sole job is to display a message. Services can be as simple or as complex as the developer would like; sometimes combining many classes together to form a comprehensive library that can later be injected into the application.
- See Also: Service Providers
- See Also: Accessors