keizah
1 week ago
139
4
Nova

How to change DateFilter format?

Posted 1 week ago by keizah

I created DateFilter and I don't find solution to change dataPicker format to Y-m-d H:i

<?php

namespace App\Nova\Filters;

use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Laravel\Nova\Filters\DateFilter;

class StartedAtFilter extends DateFilter
{

    /**
     * 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)
    {
        $value = Carbon::parse($value);
        $nextDay = Carbon::parse($value)->addDay();

        return $query->where('started_at', '>=', $value)->where('started_at', '<=', $nextDay);
    }
}

component in nova files has hardcoded format

<template>
  <div>
    <h3 class="text-sm uppercase tracking-wide text-80 bg-30 p-3">
      {{ filter.name }}
    </h3>

    <div class="p-2">
      <date-time-picker
        class="w-full form-control form-input form-input-bordered"
        dusk="date-filter"
        name="date-filter"
        autocomplete="off"
        :value="value"
        alt-format="Y-m-d"
        date-format="Y-m-d"
        :placeholder="placeholder"
        :enable-time="false"
        :enable-seconds="false"
        :first-day-of-week="firstDayOfWeek"
        @input.prevent=""
        @change="handleChange"
      />
    </div>
  </div>
</template>

Is there way to achieve my target without editing source files?

Please sign in or create an account to participate in this conversation.