Laravel/Livewire 如果今天介于 2 个日期之间,则显示 table 的数据
Laravel/Livewire display data on table if today is between 2 dates
如果今天在发布日期和截止日期之间,我正在尝试用数据填充我的 table。
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;
}
我遇到了这个错误
SQLSTATE[42S22]: Column not found: 1054 Unknown column '2022-05-06 01:10:12' in 'where clause'
另外,如果我尝试在 blade 上显示 $today
、$posting
和 $closing
,它们都会显示今天的日期。
我通过编辑我的渲染并放置 >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'));
}
您必须在查询中输入列名,不能在列名字段中输入日期
$this->career = Career::where('column_name', '<=', $this->today) ->where('column_name', '<=', $this->today)->get();
如果今天在发布日期和截止日期之间,我正在尝试用数据填充我的 table。
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;
}
我遇到了这个错误
SQLSTATE[42S22]: Column not found: 1054 Unknown column '2022-05-06 01:10:12' in 'where clause'
另外,如果我尝试在 blade 上显示 $today
、$posting
和 $closing
,它们都会显示今天的日期。
我通过编辑我的渲染并放置 >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'));
}
您必须在查询中输入列名,不能在列名字段中输入日期
$this->career = Career::where('column_name', '<=', $this->today) ->where('column_name', '<=', $this->today)->get();