Menu

Laravel Rust has no lazy loading. Here's how relationships work instead
📰

Laravel Rust has no lazy loading. Here's how relationships work instead

DEV Community: laravel·Al Nahian·1 day ago
#T79zO9Pt
#devtolaravel#devto#dev#book#loans
Long article (776 words) — no AI summary yet.
Reading 0:00
15s threshold

Eloquent will happily run a query the moment you touch $book->loans . That convenience is also how a list page ends up running 200 queries. Laravel Rust, the Rust version of Laravel that went into beta on 1 December 2026, takes the opposite position: a relationship is never loaded unless you asked for it.

Here's what that looks like in practice, using a small library app: branches hold books, members borrow them, and books have authors.

Relationships are struct fields

In Eloquent a relationship is a method. In Laravel Rust it's a field with an attribute, and the type says what's in it:

use laravel :: model :: { BelongsTo , HasMany , model } ;

use crate :: models :: { Branch , Loan } ;

#[model] pub struct Book { pub id : i64 , pub branch_id : i64 , pub title : String ,

#[belongs_to] pub branch : BelongsTo < Branch > , #[has_many] pub loans : HasMany < Loan > , }

Enter fullscreen mode

Exit fullscreen mode

The conventions are the Eloquent ones.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.