Category: Laravel

One of the most common performance issues I’ve seen in Laravel is using Eloquent methods and relationships from Blade, creating unnecessary extra loops and queries.
@foreach ($posts as $post) {{ $post->title }} @foreach ($post->tags as $tag) {{ $tag->name }} @endforeach @endforeachGuess what – same thing applies here.
public function user() { return $this->belongsTo(User::class)->withDefault(); }This withDefault() method will return empty model of User class, if the relationship doesn’t exist.
public function user() { return $this->belongsTo(User::class) ->withDefault(['name' => 'Anonymous']); }Scenario 5.
Avoiding Where Statements in Blade with Extra RelationshipsHave you seen code like this in Blade?
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners