├── .gitignore ├── src ├── DateRangePickerExtension.php ├── DateRangePickerServiceProvider.php └── DateRangePicker.php ├── composer.json ├── LICENSE ├── resources ├── views │ └── daterangepicker.blade.php └── assets │ ├── daterangepicker.css │ └── daterangepicker.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | phpunit.phar 3 | /vendor 4 | composer.phar 5 | composer.lock 6 | *.project 7 | .idea/ -------------------------------------------------------------------------------- /src/DateRangePickerExtension.php: -------------------------------------------------------------------------------- 1 | =7.0.0", 16 | "encore/laravel-admin": "~1.6" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "~6.0" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Encore\\DateRangePicker\\": "src/" 24 | } 25 | }, 26 | "extra": { 27 | "laravel": { 28 | "providers": [ 29 | "Encore\\DateRangePicker\\DateRangePickerServiceProvider" 30 | ] 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jens Segers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /resources/views/daterangepicker.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 | @include('admin::form.error') 8 | 9 |
10 | 11 | 12 | 13 | @if($multiple) 14 | 15 | 16 | 17 | 18 | 19 | @else 20 | 21 | @endif 22 | 23 | 24 |
25 | 26 | @include('admin::form.help-block') 27 | 28 |
29 |
-------------------------------------------------------------------------------- /src/DateRangePickerServiceProvider.php: -------------------------------------------------------------------------------- 1 | views()) { 21 | $this->loadViewsFrom($views, 'laravel-admin-daterangepicker'); 22 | } 23 | 24 | if ($this->app->runningInConsole() && $assets = $extension->assets()) { 25 | $this->publishes( 26 | [$assets => public_path('vendor/laravel-admin-ext/daterangepicker')], 27 | 'laravel-admin-daterangepicker' 28 | ); 29 | } 30 | 31 | Admin::booting(function () { 32 | Form::extend('daterangepicker', DateRangePicker::class); 33 | 34 | if ($alias = DateRangePickerExtension::config('alias')) { 35 | Form::alias('daterangepicker', $alias); 36 | } 37 | }); 38 | } 39 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Integrates daterangepicker into laravel-admin 2 | ====== 3 | 4 | This is an extension to integrates [Date Range Picker](http://www.daterangepicker.com/) into laravel-admin. 5 | 6 | ## Screenshot 7 | 8 | ![qq20180914-014825](https://user-images.githubusercontent.com/1479100/45505950-8521f880-b7c0-11e8-97cf-4a792e8f4c0e.png) 9 | 10 | ## Installation 11 | 12 | ```bash 13 | composer require laravel-admin-ext/daterangepicker 14 | 15 | php artisan vendor:publish --tag=laravel-admin-daterangepicker 16 | ``` 17 | 18 | ## Configurations 19 | 20 | Open `config/admin.php`, add configurations that belong to this extension at `extensions` section. 21 | ```php 22 | 23 | 'extensions' => [ 24 | 25 | 'daterangepicker' => [ 26 | 27 | // Set to `false` if you want to disable this extension 28 | 'enable' => true, 29 | 30 | // Find more configurations http://www.daterangepicker.com/ 31 | 'config' => [ 32 | 33 | ] 34 | ] 35 | ] 36 | 37 | ``` 38 | 39 | ## Usage 40 | 41 | Use it in the form: 42 | ```php 43 | //Single column 44 | 45 | $form->daterangepicker('date_range', 'Date range'); 46 | 47 | // Predefine Date Ranges. 48 | $form->daterangepicker('date_range', 'Date range') 49 | ->ranges([ 50 | 'Today' => [Carbon::today()->toDateString(), Carbon::today()->toDateString()], 51 | 'Yesterday' => [Carbon::yesterday()->toDateString(), Carbon::yesterday()->toDateString()], 52 | 'Last 7 Days' => [Carbon::today()->subDays(6)->toDateString(), Carbon::today()->toDateString()], 53 | 'Last 14 Days' => [Carbon::today()->subDays(13)->toDateString(), Carbon::today()->toDateString()], 54 | 'Last 30 Days' => [Carbon::today()->subDays(29)->toDateString(), Carbon::today()->toDateString()], 55 | 'This Month' => [Carbon::today()->startOfMonth()->toDateString(), Carbon::today()->endOfMonth()->toDateString()], 56 | 'Last Month' => [Carbon::today()->subMonth()->firstOfMonth()->toDateString(), Carbon::today()->subMonth()->lastOfMonth()->toDateString()], 57 | ]); 58 | 59 | // multilpe column 60 | $form->daterangepicker(['created_at', 'updated_at'], 'Date range'); 61 | ``` 62 | 63 | ## Donate 64 | 65 | > Help keeping the project development going, by donating a little. Thanks in advance. 66 | 67 | [![PayPal Me](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/zousong) 68 | 69 | ![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg) 70 | 71 | License 72 | ------------ 73 | Licensed under [The MIT License (MIT)](LICENSE). 74 | -------------------------------------------------------------------------------- /src/DateRangePicker.php: -------------------------------------------------------------------------------- 1 | column = []; 54 | $this->column['start'] = $column[0]; 55 | $this->column['end'] = $column[1]; 56 | 57 | $this->label = $this->formatLabel($arguments); 58 | 59 | $this->id = $this->formatId($this->column); 60 | 61 | $this->multiple = true; 62 | } 63 | } 64 | 65 | /** 66 | * Predefine Date Ranges. 67 | * 68 | * @param array $ranges 69 | * @return $this 70 | */ 71 | public function ranges($ranges = []) 72 | { 73 | return $this->options(compact('ranges')); 74 | } 75 | 76 | /** 77 | * Set date format. 78 | * 79 | * @param $format 80 | * @return $this 81 | */ 82 | public function format($format) 83 | { 84 | $this->format = $format; 85 | 86 | return $this; 87 | } 88 | 89 | /** 90 | * {@inheritdoc} 91 | */ 92 | public function render() 93 | { 94 | array_set($this->options, 'locale.format', $this->format); 95 | 96 | $global = DateRangePickerExtension::config('config', []); 97 | 98 | $options = json_encode(array_merge($global, $this->options)); 99 | 100 | $locale = config('app.locale'); 101 | 102 | $classSelector = join('_', $this->getElementClass()); 103 | 104 | $this->script = <<