Laravel 比较日期字段和现在的日期

Laravel compare between date field and date now

我正在尝试比较保存到我的数据库的日期字段和当前日期!

圆是:

  1. 管理员将添加一个具有截止日期的新职业
  2. 当有人填写申请时 he/she 将仅在下拉列表中看到可用的工作(其截止日期小于当前日期)

这就是乔布斯模型

          protected $fillable = ['job_name','job_req', 'expire'];

这是工作迁移

          public function up()
{
    Schema::create('jobs', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('job_name');
        $table->string('job_req');
        $table->date('expire');
        $table->timestamps();
    });
}

public function down()
{
    Schema::drop('jobs');
}

这是ApplicationController.php

       public function create()
{   
    $dt = Carbon::now()->toDateString();
    $jobs = Jobs::get()->where('$dt', '<', 'expire');
    return view('post.create',compact('jobs'));
}

现在,当我打开申请表时,returns 没有任何职位,但是当我从控制器中删除 where 子句时,它运行良好!

改变

$jobs = Jobs::get()->where('$dt', '<', 'expire');

$jobs = Jobs::where('expire', '>', $dt)->get();

->get() 会立即查询,必须在它之前使用->where()。

在->get()之后使用->where,你会调用这个函数 http://laravel.com/api/5.1/Illuminate/Database/Eloquent/Collection.html#method_where