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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners