Challenge 1: Create and Dispatch a Job — Possible Solution ==================================================================== # php artisan make:job ProcessOrder // app/Jobs/ProcessOrder.php namespace App\Jobs; use App\Models\Order; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; class ProcessOrder implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public function __construct( public Order $order ) {} public function handle(): void { logger()->info("Processing order #{$this->order->id}, total: \${$this->order->total}"); } } // app/Http/Controllers/OrderController.php use App\Jobs\ProcessOrder; public function store(StoreOrderRequest $request) { $order = Order::create($request->validated()); ProcessOrder::dispatch($order); return redirect()->route('orders.show', $order); } WHY THIS WORKS -------------- - The job's constructor accepts the actual Order model directly (public Order $order), not just its ID — this is safe specifically because SerializesModels (already included in every generated Job via the `use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;` line) handles serializing just the model's identity and re-fetching a fresh copy on the worker side automatically. - ProcessOrder::dispatch($order) is called AFTER Order::create(...) succeeds — the order genuinely exists in the database by the time the job is queued, so whenever a worker eventually picks it up, $this->order (re-fetched fresh via SerializesModels) reflects the order's actual current state at that later moment, not a stale snapshot from when dispatch() was called. - The controller returns its redirect response immediately after dispatch() — the actual processing (whatever handle() does) happens later, on a separate queue worker, without the user waiting for it.