HackerRank LinkedList Cycle Detection Solution
A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Given a pointer to the head of a linked list, determine…
View post
Working with dates is a common task in applications of all sizes. Here, we love Laravel. It’s a great framework and it has always made database queries a delight, thanks to Eloquent, its powerful ORM. Now, with the latest version, Laravel introduces new and improved where clauses for dates, making date-based queries even more concise and readable when filtering entries by relative dates such as past, future, or today. and even today.
If we already have classic where() or even whereDate() methods, why do we need these new ones? Because they enhance the developer experience by making code more readable, maintainable, and expressive, while also reducing verbosity.
The newly introduced date-based where clauses include:
wherePast()whereNowOrPast()whereFuture()whereNowOrFuture()whereToday()whereBeforeToday()whereTodayOrBefore()whereAfterToday()whereTodayOrAfter()These methods function similarly to whereDate(), but they only require the column name as a parameter, automatically comparing it against today’s date. Let’s look at some practical examples:
Order::wherePast('order_date')->get();Lenguaje del código: PHP (php)
Order::whereNowOrPast('order_date')->get();Lenguaje del código: PHP (php)
Reservation::whereFuture('reservation_date')->get();Lenguaje del código: PHP (php)
Reservation::whereNowOrFuture('reservation_date')->get();Lenguaje del código: PHP (php)
User::whereToday('created_at')->get();Lenguaje del código: PHP (php)
User::whereBeforeToday('created_at')->get();Lenguaje del código: PHP (php)
User::whereTodayOrBefore('created_at')->get();Lenguaje del código: PHP (php)
Invoice::whereAfterToday('due_date')->get();Lenguaje del código: PHP (php)
Invoice::whereTodayOrAfter('due_date')->get();Lenguaje del código: PHP (php)
These new where clauses provide a more intuitive and readable way to query date-based records in Laravel. They simplify complex date filters and improve code maintainability, making it easier to work with time-sensitive data. If your application relies heavily on date filtering, these methods are a welcome addition to your Laravel toolkit.
wherePast() to find expired promotions, past events, or outdated listings.whereFuture() to get upcoming meetings, launches, or deadlines.whereToday() to filter logs, user activity, or orders placed today.whereBeforeToday() or whereTodayOrAfter() to track overdue and upcoming payments.whereNowOrPast() to analyze users who have already completed an action compared to those who haven’t.By integrating these new methods into your Laravel application, you can enhance readability, reduce code clutter, and improve overall efficiency when dealing with date-based queries.
A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Given a pointer to the head of a linked list, determine…
View postContinuing some of our algorithm solutions, let’s review a new LeetCode challenge: Group Anagrams Solution We all faced the “is a valid anagram” where given two strings, we should return…
View post