wheredate in laravel not working
wheredate in laravel not working
In this session, we’ll try our hand at solving the "wheredate in laravel not working" puzzle by using the computer language.
There could be any issue in script while comparing with column's value that's why wheredate method is not working. WhereDate method is used to compare a column's value against a date in laravel-
Laravel whereDate() method on created_at field
$users = User::whereDate('created_at', '=', date('Y-m-d'))->get(); return $users; //Or $users = User::whereDate('created_at', '=', '2021-8-31')->get(); return $users;
Output:
[{"id":16,"name":"Kayla","email":"kayla@example.com","email_verified_at":null,
"created_at":"2021-08-31T08:24:43.000000Z","updated_at":"2021-08-31T08:24:43.000000Z"}]This code snippet will help you to get the records from users table on the base of current (today) date. You can pass date "2021-8-31" in ('Y-M-D') format as third argument to whereDate() method to get the record of specific date from table.
-
Laravel whereDate() method on created_at field with dynamic value
//2021-08-02 $users = User::whereDate('created_at', '=', User::find(1)->created_at->toDateString())->get(); return $users; //2021-08-02 $users = User::whereDate('created_at', '=', User::find(1)->created_at->format('Y-m-d'))->get(); return $users; //Output : [{"id":16,"name":"Kayla","email":"kayla@example.com","email_verified_at":null,"created_at":"2021-08-02T08:24:43.000000Z","updated_at":"2021-08-31T08:24:43.000000Z"}]
You can pass dynamic value to whereDate method using created_at() and toDateString() method on create_at attribute. The method format() and toDataString() convert the timestamp (date and time) value into date format.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Eager loading dynamically in laravel
- Get ids in array from users table
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Get last week data in Laravel
- How to avoid duplicate entries in pivot table in Laravel
- How to set column as primary key in Laravel model
- Split an Eloquent Collection by half in Laravel
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Laravel 11 step by step instructions to upload file in storage directory and display in blade file
- How to add columns in existing table using migration in laravel
- How to get user information using hootlex/laravel-friendships package in laravel
- How to send email in Laravel 11
- JQuery each loop on json response after ajax in laravel
- Route not defined in Laravel
- How to get random string in Laravel
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to pass data to route in laravel?
- Always load the relationship data with eager loading in Laravel
- Call to undefined method Illuminate\Support\Facades\Request::all()
- Display first n record from collection in laravel view
- How to generate .env file for laravel?
- Get only 10 records from table in laravel
- Laravel insert query not working
- Array to string conversion laravel blade
- Pass variable from blade to controller Laravel