You use join so you have to choose from which table you want to order by id
->orderByDesc('domains.id')->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using this query wrapped in a cache block:
$domainProject = Cache::tags("customdomains.{$domain}")->remember("customdomains.{$domain}", now()->addHours(12), function () use ($domain) {
return Domain::select('domains.id', 'domains.name')
// where has 3 arguments: column, operator, argument to evaluate against
->where('domains.name', $domain)
// join to projects table domains project id with projects table id
->join('projects', 'domains.project_id', '=', 'projects.id')
// We order by ID and descending and then we use the first() method helper.
// The first method returns the first element in the collection that passes a given truth test
->orderBy('id', 'DESC')->first();
});
This rule is however completely ignored. The query is fired every time. Here is the backtrace:
15. /app/Http/Controllers/Published/SiteController.php:76 // ->orderBy('id', 'DESC')->first();
16. /vendor/laravel/framework/src/Illuminate/Cache/Repository.php:385
17. /app/Http/Controllers/Published/SiteController.php:77 // });
18. /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
19. /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
Why is the caching no happening?
Please or to participate in this conversation.