Reputation: 539
I am working on a laravel project now I stuck on a query. I want to use this query:
DELETE FROM on_search WHERE search_date < NOW() - INTERVAL N DAY
but cant converted into laravel like DB::table('table_name)->where(......)-> _____ ;
Upvotes: 1
Views: 2573
Reputation: 31225
You can also do date manipulation in php with the Carbon class.
// Top of file.
use Carbon\Carbon;
DB::table('table_name)->where('search_date', '<', Carbon::now()->subDay(10));
Upvotes: 0
Reputation: 10143
$days = 10;
DB::table('on_search')
->whereRaw('search_date < NOW() - INTERVAL ? DAY', [$days])
->delete();
Upvotes: 1