Get last year created records in Laravel

Updated at 18-Nov-2021, By samar

Get last year created records in Laravel

In this article, we will see how to solve "Get last year created records in Laravel".

You can get the last year created records in Laravel. You can use whereYear() method which will help you to get the previous year records from database table.
  • Get last year created records in Laravel

    App\Models\User::whereYear('created_at', date('Y', strtotime('-1 year')))->get();
    

    You can get last year records in Laravel using whereYear() method. This code snippet will return all the user records from users table which are created at previous year.

Back to code snippet queries related laravel