Laravel/PHP Articles

Articles from Laravel/PHP sites on the web

Laravel/PHP Articles
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?

Sign Up For Our Newsletter

Each Week, We curate the top Laravel/PHP articles, jobs, events and More!

We'll send you a weekly email with the latest Laravel/PHP articles, jobs and events. Please review our Code of Conduct in the meantime. Talk to you soon!