Search code examples
laravelemailswiftmailer

laravel: check the user received email today in laravel using carbon today


I want to check that the user received email on that day or not. I already create DB table(name is Email Save) to detect that email sending or not. so i try to if statement in this

if (EmailSave::where('created_at')-> Carbon::today()) {

this one didnt work. Anyone can help on this. I give my code over here


Solution

  • Your Syntax is wrong.

    Change :

    if (EmailSave::where('created_at')-> Carbon::today()) {
    

    To:

    if (EmailSave::where('created_at', Carbon::today())->exists()) {
    

    Documentation:

    1. https://laravel.com/docs/5.8/eloquent#retrieving-models
    2. https://laravel.com/docs/5.8/queries#aggregates