'Laravel/Livewire display data on table if today is between 2 dates

I'm trying to populate my table with data if today is between posting date and closing date.

public function mount(Career $career)
    {
        $this->today = Carbon::now();
        $this->posting = Carbon::parse($career->posting_date);
        $this->closing = Carbon::parse($career->closing_date);
        $this->career = Career::where($this->posting, '<=', $this->today) ->where($this->closing, '<=', $this->today)->get();
        $this->sortBy            = 'id';
        $this->sortDirection     = 'asc';
        $this->perPage           = 100;
        $this->paginationOptions = config('project.pagination.options');
        $this->orderable         = (new Career())->orderable;
        
    }

I'm getting this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '2022-05-06 01:10:12' in 'where clause'

also if I try to display $today, $posting and $closing on my blade, they all show date today.



Solution 1:[1]

I solved it by editing my render and putting >whereDate.

public function render()
{   
    $query = Career::advancedFilter([
        's'               => $this->search ?: null,
        'order_column'    => $this->sortBy,
        'order_direction' => $this->sortDirection,])
        ->whereDate('posting_date', '<=', Carbon::now())
        ->whereDate('closing_date', '>=', Carbon::now());

    $careers = $query->paginate($this->perPage);

    return view('livewire.career.vacant', compact('careers', 'query'));  
}

Solution 2:[2]

You must enter a column name in your query and you cannot enter a date in the column name field

$this->career = Career::where('column_name', '<=', $this->today) ->where('column_name', '<=', $this->today)->get();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karl Hill
Solution 2 sina khaghani