pasksak/laravel-flatpickr
Composer 安装命令:
composer require pasksak/laravel-flatpickr
包简介
A laravel clone of the javascript flatpickr package
README 文档
README
Using this package you can add a beautiful date or datetime picker into your project without touching any javascript with the power or laravel component. It is just a laravel component wrapper for the Flatpickr javascript library.
Created with ❤️ from Nepal 🇳🇵
Support
You can support me by subscribing to my YouTube channel - Laratips.
If you want me to continue developing this package and want me to develop other similar packages, then you help me financially by sending few bucks to my Wise account in Nepalese 🇳🇵 currency.
My Wise email: ashish.dhamala2015@gmail.com
If you decide to support me, the please send me your twitter handle in mail so that I can shout-out about you on twitter.
Installation
You can install the package via composer:
composer require asdh/laravel-flatpickr
You can publish the config file with:
php artisan vendor:publish --tag="flatpickr-config"
You can publish the assets with:
php artisan vendor:publish --tag="flatpickr-assets"
This is the contents of the published config file:
return [ /** * The url to be used to serve css file. * If null, it will use the one shipped with package. */ 'css_url' => env('FLATPICKR_CSS_URL', null), /** * The url to be used to serve js file. * If null, it will use the one shipped with package. */ 'js_url' => env('FLATPICKR_JS_URL', null), /** * Determines if the styles shipped with the package should be used. * Setting it to false will remove the styling for the component. * The flatpickr css will be untouched. */ 'use_style' => env('FLATPICKR_USE_STYLE', true), ];
Usage
You need to include the css and js that ships with the package in your html or blade file.
Adding Css
Include this style at the head section of your page:
@include('flatpickr::components.style')
Or you can use laravel blade component syntax:
<x-flatpickr::style />
If you want to use different url for the css then you can change it from the .env file:
FLATPICKR_CSS_URL=https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.9/flatpickr.min.css
You can even change the url from the component itself:
<x-flatpickr::style url="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.9/flatpickr.min.css" />
The url passed form the component will take more priority over the config file.
Adding Js
Similarly include this script at the bottom of your page:
@include('flatpickr::components.script')
Or you can use laravel blade component syntax:
<x-flatpickr::script />
If you want to use different url for the js then you can change it from the .env file:
FLATPICKR_JS_URL=https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.9/flatpickr.min.js
You can even change the url from the component itself:
<x-flatpickr::script url="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.9/flatpickr.min.js" />
The url passed form the component will take more priority over the config file.
Using the component
Add it to your page.
<x-flatpickr />
Yes, it's that simple. Now you have a beautiful looking date picker in your page without touching a single javascript at all.
Component props
I have made different props for this component that will be converted into the config options of the flatpickr. Make sure to look into the config options of the flatpickr.
Most of the description of the props written here are taken from the flatpickr documentation page.
id
Type: string
Set the id of the component. It will apply id to the underlying input tag. If no id is provided, it will use the autogenerated id.
Example:
<x-flatpickr id="laravel-flatpickr" />
dateFormat
Type: string
A string of characters which are used to define how the date will be displayed in the input box. Please check the flatpickr documentation page for the supported characters. By default the date format is Y-m-d but you can change it to other formats to like d/m/Y.
Example:
<x-flatpickr date-format="d/m/Y" />
altFormat
Type: string
Exactly the same as date format, but for the altInput field. If you want different format to be visible for the user then you can use this. By default it will use the same format as that of dateFormat.
Example:
<x-flatpickr alt-format="F j, Y" />
minDate
Type: string|Carbon
The minimum date that a user can start picking from.
You can pass a Carbon instance or a date format in string that is supported by Carbon or DateTime.
Example:
<x-flatpickr min-date="2022-02-13" /> OR <x-flatpickr :min-date="today()" /> OR <x-flatpickr :min-date="\Carbon\Carbon::parse('2022-02-13')" />
maxDate
Type: string|Carbon
The maximum date that a user can pick to.
You can pass a Carbon instance or a date format in string that is supported by Carbon or DateTime.
Example:
<x-flatpickr max-date="2022-09-18" /> OR <x-flatpickr :max-date="today()" /> OR <x-flatpickr :max-date="today()->subDays(20)" />
showTime
Type: bool
Shows the time picker.
Example:
<x-flatpickr show-time />
timeFormat
Type: string
A string of characters which are used to define how the time will be displayed in the input box. Please check the flatpickr documentation page for the supported characters. By default the time format is H-i but you can change it to other formats to like h:i.
Example:
<x-flatpickr show-time time-format="h:i" />
When you use show-time prop with alt-format, make sure to write both date and time format in the alt-format like this:
Example:
<x-flatpickr show-time time-format="h:i" alt-format="F j, Y, H:i" />
minTime
Type: string
The minimum time that a user can start picking from.
Example:
<x-flatpickr show-time min-time="13:25" />
maxTime
Type: string
The maximum time that a user can pick to.
Example:
<x-flatpickr show-time max-time="23:15" />
time24hr
Type: bool
Displays time picker in 24 hour mode without AM/PM selection when enabled. By default it is set to true. To show in 12 hour mode, set it to false.
Example:
Displays the time picker in 12 hour mode with am and pm.
<x-flatpickr show-time :time24hr="false" />
firstDayOfWeek
Type: int
Sets when the first day of the calendar should start. By default it is 0 (Sunday).
Example:
It sets the first day of the week as Monday.
<x-flatpickr :first-day-of-week="1" />
disableWeekend
Type: bool
Disable the weekend in the calendar. Saturday and Sunday are disabled.
Example:
<x-flatpickr disable-weekend />
disable
Type: array
Disable the provided dates. It can be array of date string or Carbon.
Example:
<x-flatpickr :disable="['2022-02-13', '2022-02-14']" /> OR <x-flatpickr :disable="[today(), today()->addDay()]" />
enable
Type: array
Only enable the provided dates. It can be array of date string or Carbon. All the other dates other than provided in the enable array will be disabled when used.
Example:
<x-flatpickr :enable="['2022-09-18', '2022-02-14']" /> OR <x-flatpickr :enable="[today(), today()->addDay()]" />
multiple
Type: bool
Sets the calendar mode to multiple. You will be able to select multiple dates.
Example:
<x-flatpickr multiple />
range
Type: bool
Sets the calendar mode to range. You will be able to select range of dates. If you use both multiple and range, the mode will be set to range.
By default 2 months will be visible in the dropdown when the mode is range. You can change that using visibleMonths prop.
Example:
<x-flatpickr range />
visibleMonths
Type: int
The number of months to be shown at the same time when displaying the calendar.
Example:
<x-flatpickr :visible-months="3" />
inline
Type: bool
Displays the calendar inline.
Example:
<x-flatpickr inline />
showWeekNumbers
Type: bool
Shows week numbers in calendar.
Example:
<x-flatpickr show-week-numbers />
value
Type: string|Carbon|array
Sets the initial selected date(s).
Example:
For a single picker, pass normal date string or Carbon instance.
<x-flatpickr value="2022-09-18" /> OR <x-flatpickr :value="\Carbon\Carbon::parse('2022-09-18')" />
Example
For multiple picker, pass the data as array.
<x-flatpickr :value="['2022-09-18']" multiple /> OR <x-flatpickr :value="[\Carbon\Carbon::parse('2022-09-18')]" multiple />
Example
For range picker, pass the 2 dates as string separated by to in between. Or pass 2 dates as array and it will select all the dates between and including them.
<x-flatpickr value="2022-09-18 to 2022-10-11" range /> OR <x-flatpickr :value="['2022-09-18', '2022-10-11']" range />
clearable
Type: bool
Shows a clear icon on the right side of the date picker. Clicking on it will clear the selected value.
Example:
<x-flatpickr clearable />
locale
Type: string
Add locale language localization. Before that it's needed add the proper locale .js src line script in the script.blade.php file in the published vendor dir of the laravel project.
Example
For italian language add the following line just next the first <script src="{{ $url ?? config('flatpickr.js_url') ?? asset('vendor/flatpickr/js/flatpickr.js') }}"></script> at the script.blade.php file
<script src="https://npmcdn.com/flatpickr/dist/l10n/it.js"></script>
and add 'locale='it' at the flatpickr component
<x-flatpickr locale='it' />
Event Hooks
You can pass all the event hooks present in the flatpickr library like onChange, onOpen, onClose, etc. Please check all the hooks available in their documentation page.
Example:
<x-flatpickr clearable onChange="handleChange" /> <script> function handleChange(selectedDates, dateStr, instance) { console.log({ selectedDates, dateStr, instance }); } </script>
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
pasksak/laravel-flatpickr 适用场景与选型建议
pasksak/laravel-flatpickr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「asdh」 「laravel-flatpickr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pasksak/laravel-flatpickr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pasksak/laravel-flatpickr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pasksak/laravel-flatpickr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A laravel clone of the javascript flatpickr package
Alfabank REST API integration
A simple package to send mail notification to the user when their password is changed.
IME Pay payment validation package
Just a new way to save data in the database
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-04





