A Laravel clone of the Javascript Flatpickr (Date picker) library

Overview

A Laravel clone of the Javascript Flatpickr (Date picker) library

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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: [email protected]

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.

Laravel Flatpickr

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:

OR OR ">
<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:

OR OR ">
<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 />

Laravel Flatpickr

disable

Type: array

Disable the provided dates. It can be array of date string or Carbon.

Example:

OR ">
<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:

OR ">
<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 />

Laravel Flatpickr

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 />

Laravel Flatpickr

visibleMonths

Type: int

The number of months to be shown at the same time when displaying the calendar.

Example:

">
<x-flatpickr :visible-months="3" />

Laravel Flatpickr

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.

OR ">
<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.

OR ">
<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.

OR ">
<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 />

Laravel Flatpickr

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.

Comments
Releases(1.0.5)
  • 1.0.5(Aug 3, 2022)

  • 1.0.1(Feb 13, 2022)

    What's Changed

    • Add Support for Laravel 9 by @Laratipsofficial in https://github.com/Laratipsofficial/laravel-flatpickr/pull/1

    New Contributors

    • @Laratipsofficial made their first contribution in https://github.com/Laratipsofficial/laravel-flatpickr/pull/1

    Full Changelog: https://github.com/Laratipsofficial/laravel-flatpickr/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Feb 13, 2022)

Owner
Laratips
Laratips is the place to learn about web development from basics to advanced.
Laratips
A media picker plugin for Filament Admin.

Filament Curator A media picker plugin for Filament Admin. ‼️ This package is still in development ‼️ This package does not work with Spatie Media Lib

Adam Weston 84 Jan 7, 2023
Laravel Seeable - Keep track of the date and time a user was last seen.

Laravel Seeable This package makes it easy to keep track of the date and time a user was last seen. Installation Install this package. composer requir

Zep Fietje 29 Dec 26, 2022
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
AliExpress Clone app built with Laravel 8 And vuejs

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Laravue 9 Dec 21, 2022
Laravel Livewire package for clone screen with the help of websocket

screen-wire This is a Laravel Livewire package. It allow you to see what users are doing on their screen. Installation composer require mrbohem/scree

Shivam Upadhyay 2 Aug 29, 2022
Twitter clone project being developed by using PHP Laravel Framework and tailwind.css

Twits! About Twits! We, as enthusiastic learners and new developers, kicked of this project in order to improve our skills and capabilities in PhP Lar

Furkan Meraloğlu 10 Aug 29, 2022
🧱 A Roblox clone written in PHP powered by the Laravel framework.

Laravel Roblox Clone Originally written in June-July 2021 to get better with Laravel and to have something fun to work on. If you need any help, feel

Snoot 6 Dec 19, 2022
Remita Clone for PHP-CURL Developers

REMITA - Empower your Customers to pay you easily as you grow Description Remita clone app (PHP) was build to ease programmers to integerate remita pa

Abdurrahim Yahya Muazu 4 Mar 31, 2022
Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Lavacharts 3.1.12 Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API. Stable: Dev: Developer Note Please don't be di

Kevin Hill 616 Dec 17, 2022
Laravel routes from Javascript

Laravel Javascript Routes Why? I love the Laravel 4 routing system and I often use named routes like route('users.show', array('id' => 1)) to generate

Fede Isas 63 Oct 10, 2022
A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL

A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL Install To get started with SweetAle

Rashid Ali 939 Jan 8, 2023
Use ESM with importmap to manage modern JavaScript in Laravel without transpiling or bundling

Introduction Use ESM with importmap to manage modern JavaScript in Laravel without transpiling or bundling. Inspiration This package was inspired by t

Tony Messias 91 Dec 30, 2022
Video Chat application built using Metered Video SDK, with PHP Laravel Backend and JavaScript Front-End

Group Video Chat App with PHP Laravel and JavaScript Powered by Metered Video SDK Overview This application is a highly scalable group video calling a

null 2 Aug 18, 2022
Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Jameson Lopp 28 Dec 19, 2022
Simplifies writing DocBlock comments in Javascript, PHP, CoffeeScript, Actionscript, C & C++

DocBlockr DocBlockr is a package for Sublime Text 2 & 3 which makes writing documentation a breeze. DocBlockr supports JavaScript (including ES6), PHP

Nick Fisher 3.1k Nov 25, 2022
Register for multiple Livestorm sessions from an external form. Practical use of Livestorm API with PHP/Javascript.

Livestorm Multi Session Registration Register for multiple Livestorm sessions from an external form. Practical use of Livestorm API with PHP/Javascrip

Nathan CHEVALIER 0 Dec 24, 2021
Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaScript, Bootstrap e Mysql.

StampGeek Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaSc

Pablo Silva 1 Jan 13, 2022
The Most Popular JavaScript Calendar as a Filament Widget 💛

The Most Popular JavaScript Calendar as a Filament Widget ?? Features Accepts all configurations from FullCalendar Event click and drop events Upcomin

Guilherme Saade 62 Dec 31, 2022
PcTools is a proyect developed using {JavaScript,HTML5,CSS} for frontend and {PHP => Mysql} for backend.

PcTools-Proyect PcTools is a proyect developed using {JavaScript,HTML5,CSS} for frontend and {PHP => Mysql} for backend. Future Improvements # Replace

Ihab Fallahy 1 Feb 5, 2022