Backend

Laravel 13: New Features Explained with Practical Examples

July 11, 202612 min read
Laravel 13 New Features

Laravel 13 is officially here. Far from being a minimal release, it establishes a native foundation for AI tasks, vector queries, first-party JSON:API resources, and centralized routing configurations. Let's look at how to use these new capabilities in your daily development through clear, practical examples.

As modern backend requirements shift toward AI integration and structured REST protocols, frameworks must evolve to prevent codebases from becoming cluttered with custom wrapper packages. Laravel 13 addresses this directly by integrating high-level AI and vector primitives directly into the core framework.

1. The First-Party AI SDK: Building a Customer Support Agent

Instead of dragging in heavy SDKs for OpenAI, Anthropic, or Gemini, Laravel 13 features a native, unified AI SDK. This allows you to build agents that support multi-provider setups out of the box. Let's build a Support Agent that automatically routes user requests:

namespace App\Ai\Agents;

use Laravel\Ai\Agent;

class SupportAgent extends Agent
{
    public function instructions(): string
    {
        return 'You are a helpful customer support agent. Categorize the user request.';
    }
}

To run this support agent in your controller:

use App\Ai\Agents\SupportAgent;

$agent = SupportAgent::make();
$response = $agent->prompt('I need help resetting my account password.');

return (string) $response;

2. Vector Embeddings & Similarity Search using pgvector

If you are building recommendation engines, semantic searches, or semantic match layers, you no longer need external database configurations like Pinecone. Laravel 13 includes built-in support for PostgreSQL's pgvector extension.

You can generate vector embeddings directly using the Str helper, then run vector query matching using whereVectorSimilarTo():

use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;

// 1. Generate Embeddings Vector
$vector = Str::of('Laravel route optimization models')->toEmbeddings();

// 2. Execute similarity search in database
$results = DB::table('articles')
    ->whereVectorSimilarTo('embedding', 'Laravel route optimization models')
    ->limit(5)
    ->get();

3. Centralized Queue Routing

In Laravel 12, routing queue connections required hardcoding parameters inside every job file. Laravel 13 resolves this by adding central queue configurations. This allows you to manage all queues cleanly in your AppServiceProvider:

use Illuminate\Support\Facades\Queue;
use App\Jobs\ProcessVideo;
use App\Jobs\SendAlert;

// Centralized queue dispatch configurations
Queue::route(ProcessVideo::class, connection: 'sqs', queue: 'transcode');
Queue::route(SendAlert::class, connection: 'redis', queue: 'urgent');

4. Standardizing API Layouts with First-Party JSON:API Resources

Writing JSON:API compliant resources formerly meant writing large formatting helpers or maintaining custom logic. With Laravel 13, first-party support for JSON:API response wrapping is integrated natively into Illuminate\Http\Resources:

use Illuminate\Http\Resources\JsonApi\JsonApiResource;

class UserResource extends JsonApiResource
{
    // Serializes relations and sparse attributes to match JSON:API standard spec
}

5. Cache sliding TTL with touch()

Extending cache times dynamically without reloading data is now supported using the new touch() function. This extends your cache TTL cleanly and atomically:

use Illuminate\Support\Facades\Cache;

// Extends user login state session cache by 15 minutes atomically
Cache::touch('session:user:124', 900);

Need a Robust Laravel Backend?

We build enterprise-ready web applications, SaaS platforms, and cloud APIs using cutting-edge Laravel architectures. Let's discuss how we can supercharge your backend infrastructure.