Sample of Laravel Jobs and Services. For Fresno Laravel Meetup.
Single purpose models which encapsulate some arbitrary business logic.
- Provides Mechanism to slim down controller/models/views.
- Provides easy to maintain Service that can be reused by both System and Users.
- Easily testable and mockable.
- KISS and SOLID as possible.
- Logic is functional as possible.
- One entry point and one call to process.
- Contains Business related rules.
- Uses Dependency Injection to work with other components of you system (like Models and other Services) when need be.
- Welcome Email Services (POPO With Job): https://github.com/michaelachrisco/lara-services/blob/master/lara-services/app/Services/SendWelcomeEmailService.php
- Video Download Service (POPO):
- Attach Video to Eloquent model and User (Interactor)
- User Downloads a Video (2+3 as Interactor Organizer within a Job).
- POPO: Plain old PHP object. Nothing special except only one entry point. Usually contains only two methods: construct() and call().
- Interactors: Thoughtbot-like-Interactors for Services that need context from other internal models.
- Lara Jobs: Best explanation: https://laravel.com/docs/master/queues
- Command Service: Only job is to set and execute Services. Interactor Organizer is an example.
- Sending multiple User emails.
- Reporting and failed jobs.
- Timed Cron jobs.
- deefour/interactor: PHP version of https://github.com/collectiveidea/interactor
- tightenco/Mailthief: Testing Email Service with https://github.com/tightenco/mailthief
- vladahejda/phpunit-assert-exception: Testing Exceptions within Services with https://github.com/VladaHejda/PhpUnitAssertException