-
-
Save tristanbailey/614109999ab24064c5cde3e9472d86d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Nova\Filters; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Carbon; | |
use Illuminate\Container\Container; | |
use Laravel\Nova\Filters\DateFilter as NovaDateFilter; | |
class DateFilter extends NovaDateFilter | |
{ | |
public $column; | |
public function __construct($name, $column) | |
{ | |
$this->name = $name; | |
$this->column = $column; | |
} | |
/** | |
* Get the key for the filter. | |
* | |
* @return string | |
*/ | |
public function key() | |
{ | |
return "date_filter_{$this->column}"; | |
} | |
/** | |
* Apply the filter to the given query. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Illuminate\Database\Eloquent\Builder $query | |
* @param mixed $value | |
* @return \Illuminate\Database\Eloquent\Builder | |
*/ | |
public function apply(Request $request, $query, $value) | |
{ | |
if ($this->column == 'created_at') { | |
$query->where($this->column, '<', Carbon::parse($value)); | |
} | |
if ($this->column == 'updated_at') { | |
$query->where($this->column, '>', Carbon::parse($value)); | |
} | |
return $query; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment