├── config └── slider.php ├── src ├── Resources │ ├── assets │ │ ├── images │ │ │ └── dem1.jpg │ │ ├── css │ │ │ └── custome.css │ │ └── js │ │ │ └── custome.js │ └── views │ │ ├── show.blade.php │ │ ├── preview.blade.php │ │ ├── create.blade.php │ │ ├── index.blade.php │ │ └── edit.blade.php ├── Exceptions │ ├── FileCannotBeAdded.php │ ├── CustomException.php │ ├── SliderCannotBeDeleted.php │ ├── FileCannotBeAdded │ │ └── RequestDoesNotHaveFile.php │ ├── Hendler.php │ └── CustomHandler.php ├── Facades │ └── Slider.php ├── Routes │ └── web.php ├── Helpers │ ├── IOHelpers.php │ └── EloquentHelpers.php ├── SliderEntitie.php ├── Slider.php ├── SliderImage.php ├── Classes │ └── SliderClass.php ├── Requests │ ├── StoreSliderRequest.php │ └── StoreSlidesRequest.php ├── ImageSliderServiceProvider.php └── Controller │ └── SliderController.php ├── vendor ├── composer │ ├── autoload_psr4.php │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_static.php │ ├── LICENSE │ ├── autoload_real.php │ └── ClassLoader.php └── autoload.php ├── .gitignore ├── composer.json ├── database └── migrations │ ├── 2017_11_22_103026_create_slider_entities_table.php │ ├── 2017_11_10_132100_create_slider_images_table.php │ └── 2017_11_10_131458_create_sliders_table.php ├── LICENSE └── README.md /config/slider.php: -------------------------------------------------------------------------------- 1 | 'layouts.app', 5 | ]; 6 | -------------------------------------------------------------------------------- /src/Resources/assets/images/dem1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webelightsolutions/laravel-slider/HEAD/src/Resources/assets/images/dem1.jpg -------------------------------------------------------------------------------- /src/Exceptions/FileCannotBeAdded.php: -------------------------------------------------------------------------------- 1 | belongsTo(Slider::class, 'entity_id'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Exceptions/FileCannotBeAdded/RequestDoesNotHaveFile.php: -------------------------------------------------------------------------------- 1 | hasMany(SliderImage::class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/SliderImage.php: -------------------------------------------------------------------------------- 1 | belongsTo(Slider::class, 'slider_id'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webelightdev/laravel-slider", 3 | "description": "configer slider from UI", 4 | "type": "library", 5 | "require": { 6 | "intervention/image": "^2.4" 7 | }, 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "jitendrabavliya", 12 | "email": "pateljitendra3fw@gmail.com" 13 | } 14 | ], 15 | "autoload": { 16 | "psr-4": { 17 | "Webelightdev\\LaravelSlider\\": "src" 18 | } 19 | }, 20 | 21 | "minimum-stability": "dev" 22 | } 23 | -------------------------------------------------------------------------------- /src/Classes/SliderClass.php: -------------------------------------------------------------------------------- 1 | where('is_active', 1)->with('slides')->first(); 21 | $sliderJsonObj = response()->json($slider); 22 | 23 | return $sliderJsonObj; 24 | } 25 | 26 | public function sliderItems() 27 | { 28 | // $slider = new SliderClass; 29 | // $slider->macro('main', function () { 30 | // return $this->$slider->findBy($attribute, $value) 31 | // ->setActiveFromRequest(); 32 | // }); 33 | // $slider->main(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Requests/StoreSliderRequest.php: -------------------------------------------------------------------------------- 1 | 'required', 28 | 'slider_type' => 'required', 29 | 'is_active' => 'required', 30 | 'auto_paly' => 'required', 31 | 'slides_per_page' => 'required', 32 | 'slider_width' => 'required', 33 | 'slider_height' => 'required' 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2017_11_22_103026_create_slider_entities_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | $table->integer('entity_id')->unsigned(); 20 | $table->string('entity_type'); 21 | $table->integer('slider_id')->unsigned(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('external_sliders'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Requests/StoreSlidesRequest.php: -------------------------------------------------------------------------------- 1 | 'required', 28 | 'title' => 'required', 29 | 'is_active' => 'required', 30 | 'caption' => 'required', 31 | 'description' => 'required', 32 | 'image_name' => 'required', 33 | 'start_date' => 'required', 34 | 'end_date' => 'required' 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Exceptions/Hendler.php: -------------------------------------------------------------------------------- 1 | view('', [], 500); 19 | } 20 | 21 | //check if exception is an instance of ModelNotFoundException. 22 | if ($exception instanceof ModelNotFoundException) { 23 | // ajax 404 json feedback 24 | if ($request->ajax()) { 25 | return response()->json(['error' => 'Not Found'], 404); 26 | } 27 | 28 | // normal 404 view page feedback 29 | return response()->view('', [], 404); 30 | } 31 | 32 | return parent::render($request, $exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Resources/assets/js/custome.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // Variable to store your files 4 | var files; 5 | var text; 6 | var startDate; 7 | var sliderName; 8 | 9 | // Add events 10 | $('input[type=file]').on('change', function(event) { 11 | files = event.target.files; 12 | 13 | // Create a formdata object and add the files 14 | var data = new FormData(); 15 | 16 | 17 | 18 | $.each(files, function(key, value) { 19 | data.append(key, value); 20 | }); 21 | 22 | 23 | 24 | $sliderImageRequest = $.ajax({ 25 | url: '/slides/preview', 26 | type: 'POST', 27 | data: data, 28 | cache: false, 29 | dataType: 'html', 30 | processData: false, // Don't process the files 31 | contentType: false, // Set content type to false as jQuery will tell the server its a 32 | }); 33 | 34 | $sliderImageRequest.then(function(response) { 35 | $("#gallery").html(response); 36 | 37 | }); 38 | 39 | }); 40 | }); 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Webelight Solutions 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Nils Adermann, Jordi Boggiano 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is furnished 9 | to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /database/migrations/2017_11_10_132100_create_slider_images_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | $table->integer('slider_id'); 20 | $table->longtext('title')->nullable(); 21 | $table->longtext('description')->nullable(); 22 | $table->longtext('caption')->nullable(); 23 | $table->longtext('image_name'); 24 | $table->dateTime('start_date')->default(date("Y-m-d H:i:s")); 25 | $table->dateTime('end_date')->default(date("Y-m-d H:i:s")); 26 | $table->boolean('is_active')->default(1); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('slider_images'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Resources/views/show.blade.php: -------------------------------------------------------------------------------- 1 | @extends(Config::get('slider.appFileLocation')) 2 | @section('content') 3 |
4 | 5 | 6 | 7 | @if($slider['slider_type'] == 'slider') 8 | 9 | @foreach ($slides as $key => $slide) 10 | 11 | 15 | 16 | @endforeach 17 | 18 | @endif 19 | 20 | @if($slider['slider_type'] == 'banner') 21 | 22 | 23 | @foreach ($slides as $key => $slide) 24 | 29 | 31 | @endforeach 32 | 33 | @endif 34 | 35 |
36 | @endsection -------------------------------------------------------------------------------- /database/migrations/2017_11_10_131458_create_sliders_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | $table->string('name')->nullable(); 20 | $table->enum('slider_type', ['banner', 'slider']); 21 | $table->integer('slides_per_page'); 22 | $table->boolean('auto_play')->default(0); 23 | $table->integer('slider_width')->nullable(); 24 | $table->integer('slider_height')->nullable(); 25 | $table->boolean('is_active')->default(1); 26 | $table->integer('model_id')->unsigned()->nullable()->index()->comment('Model id'); 27 | $table->string('model_type')->nullable()->index()->comment('Model Name'); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | Schema::dropIfExists('sliders'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Resources/views/preview.blade.php: -------------------------------------------------------------------------------- 1 | 2 | @foreach($images as $imageKey => $image) 3 |
4 | 5 |
X
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
24 | @endforeach 25 | 26 | 32 | -------------------------------------------------------------------------------- /src/ImageSliderServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([__DIR__.'/../config/slider.php' => config_path('slider.php')]); 18 | 19 | // Migration 20 | $this->publishes([__DIR__.'/../database/migrations' => $this->app->databasePath().'/migrations'], 'migrations'); 21 | 22 | //acess Routes 23 | include __DIR__.'/Routes/web.php'; 24 | 25 | /* $this->loadViewsFrom(__DIR__ . '/Resources/views', 'laravel-slider');*/ 26 | 27 | // to Publish assets Folder 28 | 29 | $this->publishes([__DIR__.'/Resources/assets' => public_path('vendor/assets'), 30 | ]); 31 | } 32 | 33 | /** 34 | * Register the application services. 35 | */ 36 | public function register() 37 | { 38 | $this->app->bind('slider', function () { 39 | return new SliderController(); 40 | }); 41 | 42 | /*$this->app->bind('laravel-slider', function () { 43 | return new SliderClass(); 44 | });*/ 45 | 46 | $this->app->make('Webelightdev\LaravelSlider\Controller\SliderController'); 47 | $this->loadViewsFrom(__DIR__.'/Resources/views', 'laravel-slider'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Exceptions/CustomHandler.php: -------------------------------------------------------------------------------- 1 | slider = $slider; 21 | } 22 | 23 | /** 24 | * Report or log an exception. 25 | * 26 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. 27 | * 28 | * @param \Exception $exception 29 | * @return void 30 | */ 31 | public function report(Exception $exception) 32 | { 33 | parent::report($exception); 34 | } 35 | 36 | /** 37 | * Render an exception into an HTTP response. 38 | * 39 | * @param \Illuminate\Http\Request $request 40 | * @param \Exception $exception 41 | * @return \Illuminate\Http\Response 42 | */ 43 | public function render($request, Exception $exception) 44 | { 45 | $exception = Handler::prepareException($exception); 46 | 47 | if ($exception instanceof CustomException) { 48 | return $this->showCustomErrorPage(); 49 | } 50 | 51 | return parent::render($request, $exception); 52 | } 53 | 54 | public function showCustomErrorPage() 55 | { 56 | $recentlyAdded = $this->slider->fetchLatestVehicles(0, 12); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-slider 2 | Image slider using Laravel 3 | 4 | 5 | #### Demo 6 | ![new1 1](https://user-images.githubusercontent.com/32864560/33128148-5c004364-cfb1-11e7-85bf-e88744636157.png) 7 | 8 | #### Preview 9 | ![new2 1](https://user-images.githubusercontent.com/32864560/33128164-69ca895a-cfb1-11e7-97fb-ff8dbf9558ef.png) 10 | 11 | 12 | ## Following are the step to configure Image Slider 13 | 14 | ### Step 1:Laravel slider plugin requires the following components to work correctly 15 | 16 | Intervention Image 17 | 18 | 19 | #### Step 2:copy vendor using composer 20 | 21 | composer require webelightdev/laravel-slider dev-master 22 | 23 | 24 | Or, you may manually update require block and run `composer update` 25 | 26 | "require": { 27 | 28 | "webelightdev/laravel-slider": "dev-master" 29 | } 30 | 31 | 'composer update' will be required. 32 | 33 | #### step 3: Once Laravel Slider is installed, You need to register the Service Provider in `config/app.php` Add following in `providers` list 34 | 35 | 36 | 'providers' => [ 37 | // ... 38 | Webelightdev\LaravelSlider\ImageSliderServiceProvider::class, 39 | // ... 40 | 41 | ] 42 | 43 | #### step 4: To publish the Config, Migration, Service Provider and Facades Run 44 | 45 | php artisan vendor:publish 46 | 47 | #### step 5: Finally, run migration to generate table Run 48 | 49 | php artisan migrate 50 | 51 | #### step 6: This packager Required Auth login if you don't have Auth login Run 52 | 53 | php artisan make:auth 54 | php artisan migrate 55 | 56 | #### step 7: Add following link in your blade file for load CSS and Javasript 57 | 58 | 59 | 60 | 61 | #### you can view laravel slider by writing: 62 | localhost/yourapp/slider 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 27 | if ($useStaticLoader) { 28 | require_once __DIR__ . '/autoload_static.php'; 29 | 30 | call_user_func(\Composer\Autoload\ComposerStaticInit22ffe15828887207e12b2b4801afa183::getInitializer($loader)); 31 | } else { 32 | $map = require __DIR__ . '/autoload_namespaces.php'; 33 | foreach ($map as $namespace => $path) { 34 | $loader->set($namespace, $path); 35 | } 36 | 37 | $map = require __DIR__ . '/autoload_psr4.php'; 38 | foreach ($map as $namespace => $path) { 39 | $loader->setPsr4($namespace, $path); 40 | } 41 | 42 | $classMap = require __DIR__ . '/autoload_classmap.php'; 43 | if ($classMap) { 44 | $loader->addClassMap($classMap); 45 | } 46 | } 47 | 48 | $loader->register(true); 49 | 50 | return $loader; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Helpers/EloquentHelpers.php: -------------------------------------------------------------------------------- 1 | files('temp/sliders/'); 19 | 20 | foreach ($files as $file) { 21 | $directory = Storage::disk('public')->makeDirectory($sliderName); 22 | 23 | Storage::disk('public') 24 | ->move($file, $sliderName.'/original/'.basename($file)); 25 | } 26 | EloquentHelpers::resizeImage($requestFiles, $sliderName.'/small/', 200, 200); 27 | $result['success'] = "Files have been moved successfully."; 28 | return $result; 29 | } 30 | 31 | public static function resizeImage($files, $storagePath, $width, $height) 32 | { 33 | foreach ($files as $file) { 34 | $directory = Storage::disk('public')->makeDirectory($storagePath); 35 | $image = Image::make($file); 36 | $image->resize($width, $height, function ($constraint) { 37 | $constraint->aspectRatio(); 38 | })->save(); 39 | Storage::disk('public')->put($storagePath.'/'.$file->getClientOriginalName(), $image); 40 | } 41 | } 42 | 43 | 44 | public static function uploadFile($path, $file, $storageName) 45 | { 46 | $result = []; 47 | $extension = $file->getClientOriginalExtension(); 48 | $fileName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); 49 | $fileName = IOHelpers::cleanString($fileName); 50 | $fileName = time().'_'.$fileName; 51 | $finalFileName = $path.$fileName.'.'.$extension; 52 | Storage::disk($storageName)->put($finalFileName, File::get($file)); 53 | $exists = Storage::disk($storageName)->exists($finalFileName); 54 | if ($exists) { 55 | $result['success'] = 'File has been uploaded successfully.'; 56 | } else { 57 | $result['error'] = 'File upload failed.'; 58 | } 59 | $result['fileName'] = $fileName.'.'.$extension; 60 | $result['mime'] = $file->getClientMimeType(); 61 | $result['fileExtension'] = $extension; 62 | $result['slug'] = str_slug(str_random(10)); 63 | $result['fileLocation'] = $path; 64 | return $result; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Resources/views/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends(Config::get('slider.appFileLocation')) 2 | @section('content') @component('admin.components.page') @slot('pageHeading') 3 | Slider @endslot @slot('panelHeadingLeft') Create New Slider @endslot @slot('panelHeadingRight') 4 | List of Slider @endslot @slot('panelContent') 5 |
6 |
7 | {{ csrf_field() }} 8 |
9 |
10 |
11 | 12 | 13 |
14 |
15 |
16 |
17 | 18 | 22 |
23 |
24 |
25 |
26 | 27 | 31 |
32 |
33 |
34 |
35 | 36 | 37 |
38 |
39 |
40 |
41 | 42 | 43 |
44 |
45 |
46 |
47 | 48 | 49 |
50 |
51 |
52 |
53 | 54 | 55 |
56 | 58 |
59 | 60 |
61 |
62 | 67 |
68 | 69 | 70 | @endslot @endcomponent 71 | @endsection -------------------------------------------------------------------------------- /src/Resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends(Config::get('slider.appFileLocation')) 2 | @section('content') @component('admin.components.page') @slot('pageHeading') 3 | Slider @endslot @slot('panelHeadingLeft') List of Slider @endslot @slot('panelHeadingRight') 4 | Add New Slider @endslot @slot('panelContent') 5 |
6 | @if (session('success')) 7 |
8 | 9 | Success {{ session('success') }} 10 |
11 | @elseif (session('error')) 12 |
13 | 14 | Error! {{ session('error') }} 15 |
16 | @endif 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | @if (count($sliders) > 0) 29 | 30 | 31 | @foreach ($sliders as $slider) 32 | 33 | 34 | 37 | 40 | 43 | 50 | 57 | 67 | 68 | @endforeach 69 | 70 | @else 71 | 72 | 73 | 74 | 75 | 76 | @endif 77 |
Sr.No.NameSlider Type Slides Per PageAuto PlayIs ActiveActions
{{ $counter++ }} 35 |
{{ $slider->name }}
36 |
38 |
{{ $slider->slider_type }}
39 |
41 |
{{ $slider->slides_per_page }}
42 |
44 | @if($slider->auto_play == 1) 45 |
On
46 | @else 47 |
Off
48 | @endif 49 |
51 | @if($slider->is_active == 1) 52 |
Yes
53 | @else 54 |
No
55 | @endif 56 |
58 | Preview 59 | Edit @if($slider->is_active == 0) 60 | Active @else 61 | Inactive @endif 62 |
63 | {{ csrf_field() }} {{ method_field('DELETE') }} 64 | 65 |
66 |
No Records Found.
78 |
79 |
80 | 81 | 82 | @endslot @endcomponent 83 | @endsection -------------------------------------------------------------------------------- /src/Resources/views/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends(Config::get('slider.appFileLocation')) 2 | @section('content') @component('admin.components.page') @slot('pageHeading') 3 | Slider @endslot @slot('panelHeadingLeft') Edit Slider - {{ $slider->name }} @endslot @slot('panelHeadingRight') 4 | List of Slider @endslot @slot('panelContent') 5 |
6 | {{ csrf_field() }} {{ method_field('PUT') }} 7 |
8 |
9 |
10 |
11 | 12 | 13 |
14 |
15 |
16 |
17 | 18 | 22 |
23 |
24 |
25 |
26 | 27 | 31 |
32 |
33 |
34 |
35 | 36 | 37 |
38 |
39 |
40 |
41 | 42 | 43 |
44 |
45 |
46 |
47 | 48 | 49 |
50 |
51 |
52 |
53 | 54 | 55 |
56 |
57 |
58 | @foreach($slider['slides'] as $imageKey => $slide) 59 |
60 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
76 | @endforeach 77 | 79 |
80 |
81 |
82 | 87 |
88 | 89 | 90 | 95 | @endslot @endcomponent 96 | @endsection -------------------------------------------------------------------------------- /src/Controller/SliderController.php: -------------------------------------------------------------------------------- 1 | slider = $slider; 29 | $this->sliderImage = $sliderImage; 30 | } 31 | 32 | /** 33 | * Display a listing of the resource. 34 | * 35 | * @return \Illuminate\Http\Response 36 | */ 37 | public function index() 38 | { 39 | $sliders = $this->slider->orderBy('id', 'desc')->with('slides')->get(); 40 | 41 | return view('laravel-slider::index', compact('sliders')); 42 | } 43 | 44 | /** 45 | * Show the form for creating a new resource. 46 | * 47 | * @return \Illuminate\Http\Response 48 | */ 49 | public function create(Request $request) 50 | { 51 | return view('laravel-slider::create'); 52 | } 53 | 54 | /** 55 | * Store a newly created resource in storage. 56 | * 57 | * @param \Illuminate\Http\Request $request 58 | * 59 | * @return \Illuminate\Http\Response 60 | */ 61 | public function store(Request $request) 62 | { 63 | $data = $request->all(); 64 | 65 | // Get list of file names from request as array [temp storage] 66 | $sliderImages = $data['image_name']; 67 | $sliderName = $data['name']; 68 | 69 | // Move SliderImages from temp storage to original storage 70 | $oldPath = 'temp/'.$sliderName.'/'; 71 | $targetPath = 'slide'; 72 | $resultFiles = EloquentHelpers::moveAllFiles($sliderImages, $oldPath, $targetPath, $sliderName); 73 | 74 | $path = $data['name'].'/'; 75 | try { 76 | $newSlider = $this->slider->create($data); 77 | } catch (Exception $e) { 78 | return redirect('laravel-slider::create')->with('error', $e->getMessage())->withInput(); 79 | } 80 | $date = $request->image_name; 81 | 82 | foreach ($data['slides'] as $slide) { 83 | $slide['slider_id'] = $newSlider->id; 84 | try { 85 | $this->sliderImage->create($slide); 86 | } catch (Exception $e) { 87 | return redirect('laravel-slider::create')->with('error', $e->getMessage())->withInput(); 88 | } 89 | } 90 | 91 | return redirect('slider')->with('success', 'Slider saved successfully'); 92 | } 93 | 94 | /** 95 | * Display the specified resource. 96 | * 97 | * @param int $id 98 | * 99 | * @return \Illuminate\Http\Response 100 | */ 101 | public function show($id) 102 | { 103 | $currentDate = Carbon::now(); 104 | $currentFormatedDate = $currentDate->format('Y-m-d'); 105 | $slider = $this->slider->where('id', $id)->first(); 106 | 107 | $slides = \DB::select(" 108 | SELECT * from slider_images 109 | where is_active = 1 AND slider_id = ? AND ? BETWEEN DATE_FORMAT(start_date, '%Y-%m-%d') AND DATE_FORMAT(end_date, '%Y-%m-%d')", [$slider->id, $currentFormatedDate]); 110 | 111 | return view('laravel-slider::show', compact('slides', 'slider')); 112 | } 113 | 114 | /** 115 | * Show the form for editing the specified resource. 116 | * 117 | * @param int $id 118 | * 119 | * @return \Illuminate\Http\Response 120 | */ 121 | public function edit($id) 122 | { 123 | $slider = $this->slider->where('id', $id)->with('slides')->first(); 124 | 125 | return view('laravel-slider::edit', compact('slider')); 126 | } 127 | 128 | public function preview(Request $request) 129 | { 130 | $selectedFiles = $request->all(); 131 | $folderName = 'sliders'; 132 | $path = 'temp/'.$folderName.'/'; 133 | 134 | foreach ($selectedFiles as $file) { 135 | $images[] = EloquentHelpers::uploadFile($path, $file, 'public'); 136 | } 137 | 138 | return view('laravel-slider::preview', compact('selectedFiles', 'folderName', 'images')); 139 | } 140 | 141 | /** 142 | * Update the specified resource in storage. 143 | * 144 | * @param \Illuminate\Http\Request $request 145 | * @param int $id 146 | * 147 | * @return \Illuminate\Http\Response 148 | */ 149 | public function update(Request $request, $id) 150 | { 151 | $slider = $this->slider->where('id', $id)->first(); 152 | DB::beginTransaction(); 153 | if (!$slider) { 154 | return redirect('slider')->with('error', 'Slider details does not exists.'); 155 | } 156 | 157 | $data = $request->all(); 158 | $data = $request->except(['_token', '_method']); 159 | 160 | if ($slider) { 161 | $slider->fill($data); 162 | try { 163 | $slider->save(); 164 | } catch (QueryException $e) { 165 | DB::rollback(); 166 | 167 | return redirect('laravel-slider::edit')->with('error', $e->getMessage())->withInput(); 168 | } 169 | } else { 170 | return redirect('laravel-slider::index')->with('error', $e->getMessage()); 171 | } 172 | 173 | //get list of slides id from request 174 | $inputSlidesIds = collect($data['oldSlides'])->pluck('id')->all(); 175 | 176 | //get list of slides from the database for perticular slider 177 | $existingSlidesIds = $this->sliderImage->where('slider_id', $id)->pluck('id')->all(); 178 | 179 | //get Difference between input and existing slides id 180 | $toBeDeletedSlidesIds = array_diff($existingSlidesIds, $inputSlidesIds); 181 | 182 | // Delete those slides which are found in the above difference 183 | $this->sliderImage->where('slider_id', $id)->whereIn('id', $toBeDeletedSlidesIds)->delete(); 184 | 185 | foreach ($data['oldSlides'] as $slide) { 186 | $slides = $this->sliderImage->where('slider_id', $id)->where('id', $slide['id'])->first(); 187 | if ($slides) { 188 | $slides->fill($slide); 189 | try { 190 | $slides->save(); 191 | } catch (QueryException $e) { 192 | DB::rollback(); 193 | 194 | return redirect('laravel-slider::edit')->with('error', $e->getMessage())->withInput(); 195 | } 196 | } else { 197 | try { 198 | $this->sliderImage->create($slide); 199 | } catch (QueryException $e) { 200 | DB::rollback(); 201 | 202 | return redirect('laravel-slider::index')->with('error', $e->getMessage()); 203 | } 204 | } 205 | } 206 | 207 | //New Slide Added druing edit methode 208 | if (array_has($data, 'slides')) { 209 | // Get list of file names from request as array [temp storage] 210 | $sliderImages = $data['image_name']; 211 | 212 | $sliderName = $data['name']; 213 | // Move SliderImages from temp storage to original storage 214 | $oldPath = 'temp/'.$sliderName.'/'; 215 | $targetPath = 'slide'; 216 | $resultFiles = EloquentHelpers::moveAllFiles($sliderImages, $oldPath, $targetPath, $sliderName); 217 | 218 | foreach ($data['slides'] as $slide) { 219 | $slide['slider_id'] = $id; 220 | try { 221 | $this->sliderImage->create($slide); 222 | } catch (Exception $e) { 223 | DB::rollback(); 224 | 225 | return redirect('laravel-slider::edit')->with('error', $e->getMessage())->withInput(); 226 | } 227 | } 228 | } 229 | DB::commit(); 230 | 231 | return redirect('slider')->with('success', 'Slider details updated successfully.'); 232 | } 233 | 234 | /** 235 | * Remove the specified resource from storage. 236 | * 237 | * @param int $id 238 | * 239 | * @return \Illuminate\Http\Response 240 | */ 241 | public function destroy($id) 242 | { 243 | $result = []; 244 | $slider = $this->slider->findOrFail($id)->first(); 245 | 246 | try { 247 | $this->slider->where('id', $id)->delete(); 248 | } catch (Exception $e) { 249 | return redirect('/slider')->with('error', $e->getMessage()); 250 | } 251 | 252 | return redirect('/slider')->with('success', 'Slider deleted successfully'); 253 | } 254 | 255 | public function changeSliderStatus($id) 256 | { 257 | $status = $this->slider->where('id', $id)->pluck('is_active')->first(); 258 | if ($status == 1) { 259 | try { 260 | $this->slider->find($id)->update(['is_active' => false]); 261 | 262 | return redirect('/slider'); 263 | } catch (Exception $e) { 264 | return redirect('laravel-slider::index')->with('error', $e->getMessage()); 265 | } 266 | } else { 267 | try { 268 | $this->slider->find($id)->update(['is_active' => true]); 269 | 270 | return redirect('/slider'); 271 | } catch (Exception $e) { 272 | return redirect('laravel-slider::index')->with('error', $e->getMessage()); 273 | } 274 | } 275 | } 276 | 277 | // public function get($entityType, $entityId) 278 | // { 279 | // if (isset($entityType)) { 280 | // if ($entityType == 'slider' && isset($entityId)) { 281 | // $sliders = $this->slider->where('entity_type', $entityType)->where('entity_id', $entityId)->first(); 282 | // } else { 283 | // $sliders = $this->slider->join('slider_entities')->where('entity_type', $entityType)->where('entity_id', $entityId)->get(); 284 | // } 285 | // } else { 286 | // $sliders = $this->slider->where('entity_type', $entityType)->get(); 287 | // } 288 | // return view('laravel-slider::show', compact('sliders')); 289 | // } 290 | 291 | // public function sliderEntities(Request $request) 292 | // { 293 | // DB::beginTransaction(); 294 | // try { 295 | // $this->sliderEntitie->create($request->all()) 296 | // } catch (Exception $e) { 297 | // return redirect('/slider')->with('error', $e->getMessage())->withInput(); 298 | // } 299 | 300 | // DB::commit(); 301 | // return redirect('/slider')->with('success', 'Slider stored successfully.'); 302 | // } 303 | } 304 | -------------------------------------------------------------------------------- /vendor/composer/ClassLoader.php: -------------------------------------------------------------------------------- 1 | 7 | * Jordi Boggiano 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier 39 | * @author Jordi Boggiano 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | private $classMapAuthoritative = false; 57 | private $missingClasses = array(); 58 | private $apcuPrefix; 59 | 60 | public function getPrefixes() 61 | { 62 | if (!empty($this->prefixesPsr0)) { 63 | return call_user_func_array('array_merge', $this->prefixesPsr0); 64 | } 65 | 66 | return array(); 67 | } 68 | 69 | public function getPrefixesPsr4() 70 | { 71 | return $this->prefixDirsPsr4; 72 | } 73 | 74 | public function getFallbackDirs() 75 | { 76 | return $this->fallbackDirsPsr0; 77 | } 78 | 79 | public function getFallbackDirsPsr4() 80 | { 81 | return $this->fallbackDirsPsr4; 82 | } 83 | 84 | public function getClassMap() 85 | { 86 | return $this->classMap; 87 | } 88 | 89 | /** 90 | * @param array $classMap Class to filename map 91 | */ 92 | public function addClassMap(array $classMap) 93 | { 94 | if ($this->classMap) { 95 | $this->classMap = array_merge($this->classMap, $classMap); 96 | } else { 97 | $this->classMap = $classMap; 98 | } 99 | } 100 | 101 | /** 102 | * Registers a set of PSR-0 directories for a given prefix, either 103 | * appending or prepending to the ones previously set for this prefix. 104 | * 105 | * @param string $prefix The prefix 106 | * @param array|string $paths The PSR-0 root directories 107 | * @param bool $prepend Whether to prepend the directories 108 | */ 109 | public function add($prefix, $paths, $prepend = false) 110 | { 111 | if (!$prefix) { 112 | if ($prepend) { 113 | $this->fallbackDirsPsr0 = array_merge( 114 | (array) $paths, 115 | $this->fallbackDirsPsr0 116 | ); 117 | } else { 118 | $this->fallbackDirsPsr0 = array_merge( 119 | $this->fallbackDirsPsr0, 120 | (array) $paths 121 | ); 122 | } 123 | 124 | return; 125 | } 126 | 127 | $first = $prefix[0]; 128 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 130 | 131 | return; 132 | } 133 | if ($prepend) { 134 | $this->prefixesPsr0[$first][$prefix] = array_merge( 135 | (array) $paths, 136 | $this->prefixesPsr0[$first][$prefix] 137 | ); 138 | } else { 139 | $this->prefixesPsr0[$first][$prefix] = array_merge( 140 | $this->prefixesPsr0[$first][$prefix], 141 | (array) $paths 142 | ); 143 | } 144 | } 145 | 146 | /** 147 | * Registers a set of PSR-4 directories for a given namespace, either 148 | * appending or prepending to the ones previously set for this namespace. 149 | * 150 | * @param string $prefix The prefix/namespace, with trailing '\\' 151 | * @param array|string $paths The PSR-4 base directories 152 | * @param bool $prepend Whether to prepend the directories 153 | * 154 | * @throws \InvalidArgumentException 155 | */ 156 | public function addPsr4($prefix, $paths, $prepend = false) 157 | { 158 | if (!$prefix) { 159 | // Register directories for the root namespace. 160 | if ($prepend) { 161 | $this->fallbackDirsPsr4 = array_merge( 162 | (array) $paths, 163 | $this->fallbackDirsPsr4 164 | ); 165 | } else { 166 | $this->fallbackDirsPsr4 = array_merge( 167 | $this->fallbackDirsPsr4, 168 | (array) $paths 169 | ); 170 | } 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 172 | // Register directories for a new namespace. 173 | $length = strlen($prefix); 174 | if ('\\' !== $prefix[$length - 1]) { 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 176 | } 177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 179 | } elseif ($prepend) { 180 | // Prepend directories for an already registered namespace. 181 | $this->prefixDirsPsr4[$prefix] = array_merge( 182 | (array) $paths, 183 | $this->prefixDirsPsr4[$prefix] 184 | ); 185 | } else { 186 | // Append directories for an already registered namespace. 187 | $this->prefixDirsPsr4[$prefix] = array_merge( 188 | $this->prefixDirsPsr4[$prefix], 189 | (array) $paths 190 | ); 191 | } 192 | } 193 | 194 | /** 195 | * Registers a set of PSR-0 directories for a given prefix, 196 | * replacing any others previously set for this prefix. 197 | * 198 | * @param string $prefix The prefix 199 | * @param array|string $paths The PSR-0 base directories 200 | */ 201 | public function set($prefix, $paths) 202 | { 203 | if (!$prefix) { 204 | $this->fallbackDirsPsr0 = (array) $paths; 205 | } else { 206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 207 | } 208 | } 209 | 210 | /** 211 | * Registers a set of PSR-4 directories for a given namespace, 212 | * replacing any others previously set for this namespace. 213 | * 214 | * @param string $prefix The prefix/namespace, with trailing '\\' 215 | * @param array|string $paths The PSR-4 base directories 216 | * 217 | * @throws \InvalidArgumentException 218 | */ 219 | public function setPsr4($prefix, $paths) 220 | { 221 | if (!$prefix) { 222 | $this->fallbackDirsPsr4 = (array) $paths; 223 | } else { 224 | $length = strlen($prefix); 225 | if ('\\' !== $prefix[$length - 1]) { 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 227 | } 228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 230 | } 231 | } 232 | 233 | /** 234 | * Turns on searching the include path for class files. 235 | * 236 | * @param bool $useIncludePath 237 | */ 238 | public function setUseIncludePath($useIncludePath) 239 | { 240 | $this->useIncludePath = $useIncludePath; 241 | } 242 | 243 | /** 244 | * Can be used to check if the autoloader uses the include path to check 245 | * for classes. 246 | * 247 | * @return bool 248 | */ 249 | public function getUseIncludePath() 250 | { 251 | return $this->useIncludePath; 252 | } 253 | 254 | /** 255 | * Turns off searching the prefix and fallback directories for classes 256 | * that have not been registered with the class map. 257 | * 258 | * @param bool $classMapAuthoritative 259 | */ 260 | public function setClassMapAuthoritative($classMapAuthoritative) 261 | { 262 | $this->classMapAuthoritative = $classMapAuthoritative; 263 | } 264 | 265 | /** 266 | * Should class lookup fail if not found in the current class map? 267 | * 268 | * @return bool 269 | */ 270 | public function isClassMapAuthoritative() 271 | { 272 | return $this->classMapAuthoritative; 273 | } 274 | 275 | /** 276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled. 277 | * 278 | * @param string|null $apcuPrefix 279 | */ 280 | public function setApcuPrefix($apcuPrefix) 281 | { 282 | $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; 283 | } 284 | 285 | /** 286 | * The APCu prefix in use, or null if APCu caching is not enabled. 287 | * 288 | * @return string|null 289 | */ 290 | public function getApcuPrefix() 291 | { 292 | return $this->apcuPrefix; 293 | } 294 | 295 | /** 296 | * Registers this instance as an autoloader. 297 | * 298 | * @param bool $prepend Whether to prepend the autoloader or not 299 | */ 300 | public function register($prepend = false) 301 | { 302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 303 | } 304 | 305 | /** 306 | * Unregisters this instance as an autoloader. 307 | */ 308 | public function unregister() 309 | { 310 | spl_autoload_unregister(array($this, 'loadClass')); 311 | } 312 | 313 | /** 314 | * Loads the given class or interface. 315 | * 316 | * @param string $class The name of the class 317 | * @return bool|null True if loaded, null otherwise 318 | */ 319 | public function loadClass($class) 320 | { 321 | if ($file = $this->findFile($class)) { 322 | includeFile($file); 323 | 324 | return true; 325 | } 326 | } 327 | 328 | /** 329 | * Finds the path to the file where the class is defined. 330 | * 331 | * @param string $class The name of the class 332 | * 333 | * @return string|false The path if found, false otherwise 334 | */ 335 | public function findFile($class) 336 | { 337 | // class map lookup 338 | if (isset($this->classMap[$class])) { 339 | return $this->classMap[$class]; 340 | } 341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 342 | return false; 343 | } 344 | if (null !== $this->apcuPrefix) { 345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit); 346 | if ($hit) { 347 | return $file; 348 | } 349 | } 350 | 351 | $file = $this->findFileWithExtension($class, '.php'); 352 | 353 | // Search for Hack files if we are running on HHVM 354 | if (false === $file && defined('HHVM_VERSION')) { 355 | $file = $this->findFileWithExtension($class, '.hh'); 356 | } 357 | 358 | if (null !== $this->apcuPrefix) { 359 | apcu_add($this->apcuPrefix.$class, $file); 360 | } 361 | 362 | if (false === $file) { 363 | // Remember that this class does not exist. 364 | $this->missingClasses[$class] = true; 365 | } 366 | 367 | return $file; 368 | } 369 | 370 | private function findFileWithExtension($class, $ext) 371 | { 372 | // PSR-4 lookup 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 374 | 375 | $first = $class[0]; 376 | if (isset($this->prefixLengthsPsr4[$first])) { 377 | $subPath = $class; 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { 379 | $subPath = substr($subPath, 0, $lastPos); 380 | $search = $subPath.'\\'; 381 | if (isset($this->prefixDirsPsr4[$search])) { 382 | foreach ($this->prefixDirsPsr4[$search] as $dir) { 383 | $length = $this->prefixLengthsPsr4[$first][$search]; 384 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 385 | return $file; 386 | } 387 | } 388 | } 389 | } 390 | } 391 | 392 | // PSR-4 fallback dirs 393 | foreach ($this->fallbackDirsPsr4 as $dir) { 394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 395 | return $file; 396 | } 397 | } 398 | 399 | // PSR-0 lookup 400 | if (false !== $pos = strrpos($class, '\\')) { 401 | // namespaced class name 402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 404 | } else { 405 | // PEAR-like class name 406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 407 | } 408 | 409 | if (isset($this->prefixesPsr0[$first])) { 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 411 | if (0 === strpos($class, $prefix)) { 412 | foreach ($dirs as $dir) { 413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 414 | return $file; 415 | } 416 | } 417 | } 418 | } 419 | } 420 | 421 | // PSR-0 fallback dirs 422 | foreach ($this->fallbackDirsPsr0 as $dir) { 423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 424 | return $file; 425 | } 426 | } 427 | 428 | // PSR-0 include paths. 429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 430 | return $file; 431 | } 432 | 433 | return false; 434 | } 435 | } 436 | 437 | /** 438 | * Scope isolated include. 439 | * 440 | * Prevents access to $this/self from included files. 441 | */ 442 | function includeFile($file) 443 | { 444 | include $file; 445 | } 446 | --------------------------------------------------------------------------------