@@ -498,7 +498,7 @@ This is useful for dashboard widgets or front-end frameworks.
498498
499499For more complex apps, move logic into a service class:
500500
501- Create ` app/Services/PostPublisher .php ` :
501+ Create ` app/Services/PostPublisherService .php ` :
502502
503503``` php
504504<?php
@@ -509,7 +509,7 @@ namespace App\Services;
509509
510510use App\Models\Post;
511511
512- final class PostPublisher
512+ final class PostPublisherService
513513{
514514 /** @param array<string , mixed > $data */
515515 public function publish(array $data): Post
@@ -520,10 +520,18 @@ final class PostPublisher
520520}
521521```
522522
523+ You can generate a service class with:
524+
525+ ``` bash
526+ php pipeflow make:service PostPublisher
527+ ```
528+
529+ This creates ` app/Services/PostPublisherService.php ` .
530+
523531Then inject it in your controller:
524532
525533``` php
526- public function store(Request $request, PostPublisher $publisher, Conn $conn): Response
534+ public function store(Request $request, PostPublisherService $publisher, Conn $conn): Response
527535{
528536 $data = $request->only(['title', 'body']);
529537 $errors = $this->validate($data);
@@ -541,6 +549,32 @@ public function store(Request $request, PostPublisher $publisher, Conn $conn): R
541549}
542550```
543551
552+ ### When to use services (external APIs, AI, cloud)
553+
554+ Services are the right place to integrate with third‑party APIs (payment, email, cloud storage, AI). They should:
555+
556+ - Accept plain data in method arguments (avoid storing request-specific state).
557+ - Wrap external SDK clients (Stripe, OpenAI, S3) behind a tiny interface.
558+ - Return plain PHP arrays or value objects so controllers remain thin.
559+
560+ Example skeleton for an external API service:
561+
562+ ``` php
563+ namespace App\Services;
564+
565+ final class AiSummaryService
566+ {
567+ public function summarize(string $text): string
568+ {
569+ // Call a 3rd-party SDK or HTTP client here.
570+ // Return a string so controllers/views stay simple.
571+ return $text;
572+ }
573+ }
574+ ```
575+
576+ If you need framework config, read it inside the method (or inject via constructor) and keep the service stateless.
577+
544578## 6.10.1) Public vs private helpers in controllers
545579
546580Keep controller actions ` public ` and push shared logic into ` private ` helpers:
@@ -782,6 +816,18 @@ php pipeflow route:list
782816
783817You’ll see all route patterns, names, and target controllers in a table.
784818
819+ Example output (indented columns):
820+
821+ ```
822+ GET /posts posts.index
823+ GET /posts/create posts.create
824+ POST /posts posts.store
825+ GET /posts/{id} posts.show
826+ GET /posts/{id}/edit posts.edit
827+ POST /posts/{id} posts.update
828+ POST /posts/{id}/delete posts.destroy
829+ ```
830+
785831## 8) Add flash feedback (optional)
786832
787833PipeFlow ships with a flash system so you can show one-time notices after redirects.
0 commit comments