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

Community Partners