├── LICENSE ├── README.md ├── composer.json ├── config └── config.php ├── database └── migrations │ └── 2015_10_31_162633_scaffoldinterfaces.php ├── resources ├── assets │ ├── css │ │ └── scaffold-interface-css │ │ │ └── main.css │ └── js │ │ └── scaffold-interface-js │ │ ├── customA.js │ │ ├── main.js │ │ ├── main2.js │ │ └── social.js └── views │ ├── graph.blade.php │ ├── scaffold.blade.php │ ├── scaffoldApp.blade.php │ └── template │ ├── DeleteMessage │ └── delete.blade.php │ ├── ManyToMany │ ├── migration.blade.php │ └── model.blade.php │ ├── controller │ └── controller.blade.php │ ├── migration │ └── migration.blade.php │ ├── model │ └── model.blade.php │ ├── routes.blade.php │ └── views │ ├── bootstrap │ ├── create.blade.php │ ├── edit.blade.php │ ├── index.blade.php │ └── show.blade.php │ └── materialize │ ├── create.blade.php │ ├── edit.blade.php │ ├── index.blade.php │ └── show.blade.php └── src ├── Attribute.php ├── Datasystem ├── Database │ ├── Database.php │ ├── DatabaseContractInterface.php │ ├── DatabaseManager.php │ ├── MysqlDatabase.php │ ├── PgsqlDatabase.php │ └── SqliteDatabase.php └── Datasystem.php ├── Events └── DeleteCrud.php ├── Filesystem ├── FileAlreadyExists.php ├── FileNotFound.php ├── Filesystem.php └── Path.php ├── Generators ├── ControllerGenerate.php ├── Generator.php ├── GeneratorInterface.php ├── MigrationGenerate.php ├── ModelGenerate.php ├── RouteGenerate.php └── ViewGenerate.php ├── Http ├── Controllers │ ├── GuiController.php │ └── ScaffoldInterfaceController.php ├── Middleware │ └── ScaffoldMiddleware.php ├── Request.php └── routes.php ├── Listeners └── DeleteCrudFiles.php ├── ManyToMany └── ManyToMany.php ├── Models ├── Relation.php └── Scaffoldinterface.php ├── Parsers └── Parser.php ├── Providers └── ScaffoldInterfaceEventServiceProvider.php ├── Publishes ├── Controllers │ └── ScaffoldInterface │ │ ├── AppController.php │ │ ├── PermissionController.php │ │ ├── RoleController.php │ │ └── UserController.php └── Views │ └── scaffold-interface │ ├── dashboard │ └── dashboard.blade.php │ ├── layouts │ ├── app.blade.php │ └── defaultMaterialize.blade.php │ ├── permissions │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php │ ├── roles │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php │ └── users │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php ├── Scaffold.php └── ScaffoldInterfaceServiceProvider.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Amrani Houssain 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![Imgur](http://i.imgur.com/9PkXGOV.jpg) 3 | [![Gitter chat](https://img.shields.io/badge/chat-gitter-F50057.svg)](https://gitter.im/amranidev-scaffold-interface/Lobby) 4 | [![Build Status](https://travis-ci.org/amranidev/scaffold-interface.svg?branch=master)](https://travis-ci.org/amranidev/scaffold-interface) 5 | [![StyleCI](https://styleci.io/repos/45497055/shield?style=flat)](https://styleci.io/repos/45497055) 6 | [![Built For Laravel](https://img.shields.io/badge/built%20for-laravel-blue.svg)](http://laravel.com) 7 | [![Total Downloads](https://poser.pugx.org/amranidev/scaffold-interface/downloads)](https://packagist.org/packages/amranidev/scaffold-interface) 8 | [![Latest Stable Version](https://poser.pugx.org/amranidev/scaffold-interface/v/stable)](https://packagist.org/packages/amranidev/scaffold-interface) 9 | [![Latest Unstable Version](https://poser.pugx.org/amranidev/scaffold-interface/v/unstable)](https://packagist.org/packages/amranidev/scaffold-interface) 10 | [![License](https://poser.pugx.org/amranidev/scaffold-interface/license)](https://packagist.org/packages/amranidev/scaffold-interface) 11 | 12 | ![Scaffold](http://i.imgur.com/65uhrP7.gif) 13 | 14 | ### Features 15 | 16 | + Generate your models, views, controllers, routes and migrations just in a few clicks. 17 | 18 | + Models visualization through a graph presentation (**New Feature**). 19 | 20 | + Views scaffolding support Bootstrap and Materialize css. 21 | 22 | + Generate (OneToMany,ManyToMany) relationships including views and controllers. 23 | 24 | + Websockets using [pusher notifications](https://www.github.com/pusher). 25 | 26 | + AdminLTE dashboard template with users management system (users-roles-permissions) using [laravel-permission](https://github.com/spatie/laravel-permission). 27 | 28 | + Softdeletes and timestamps. 29 | 30 | + A delete confirmation message. 31 | 32 | + Using an interface to design your table. 33 | 34 | + Rollback possibility. 35 | 36 | + Generate CRUD for packages, see [Lpackager](https://github.com/amranidev/lpackager), [CRUD for packages/modules](http://amranidev.github.io/blog/site/crud-generator-for-packages/). 37 | 38 | 39 | ### Installation 40 | 41 | 1. Run the following command: 42 | 43 | `composer require amranidev/scaffold-interface` 44 | 45 | 2. Add the service providers to config/app.php: 46 | 47 | ```php 48 | Amranidev\ScaffoldInterface\ScaffoldInterfaceServiceProvider::class, 49 | Amranidev\Ajaxis\AjaxisServiceProvider::class, 50 | Spatie\Permission\PermissionServiceProvider::class, 51 | Pusher\Laravel\PusherServiceProvider::class, 52 | ``` 53 | 54 | 3. Publish the assets in your application with: 55 | 56 | `php artisan vendor:publish` 57 | 58 | 4. Run migrations: 59 | 60 | `php artisan migrate` 61 | 62 | 5. Authentication scaffolding: 63 | 64 | `php artisan make:auth` 65 | 66 | 6. Add HasRole dependency to app/User.php: 67 | 68 | ```php 69 | =7.0", 14 | "Amranidev/Ajaxis": "3.0.*", 15 | "spatie/laravel-permission": "^2.7", 16 | "pusher/pusher-http-laravel": "^4.0.0", 17 | "gajus/dindent": "2.0.*" 18 | }, 19 | "require-dev": { 20 | "phpunit/phpunit": "~4.0|~5.0|~6.0", 21 | "orchestra/testbench": "~3.5.0" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "Amranidev\\ScaffoldInterface\\": "src/" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "Amranidev\\ScaffoldInterface\\Tests\\": "tests/" 31 | } 32 | }, 33 | "extra": { 34 | "branch-alias": { 35 | "dev-master": "1.8.x-dev" 36 | }, 37 | "laravel": { 38 | "providers": [ 39 | "Amranidev\\ScaffoldInterface\\ScaffoldInterfaceServiceProvider" 40 | ] 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | [ 16 | 'local', 17 | ], 18 | 19 | /* 20 | |-------------------------------------------------------------------- 21 | | Default package Name 22 | |-------------------------------------------------------------------- 23 | | 24 | | Here is where you can register your current package. 25 | | By default is Laravel 26 | | 27 | */ 28 | 29 | 'package' => 'Laravel', 30 | 31 | /* 32 | |-------------------------------------------------------------------- 33 | | Default Files Storage , (Models , Views , Controllers , Migrations) 34 | |-------------------------------------------------------------------- 35 | | 36 | | Here is where you can register your storage paths. 37 | | 38 | */ 39 | 40 | 'model' => base_path('app'), 41 | 42 | 'views' => base_path('resources/views'), 43 | 44 | 'controller' => base_path('app/Http/Controllers'), 45 | 46 | 'migration' => base_path('database/migrations'), 47 | 48 | /* 49 | |-------------------------------------------------------------------- 50 | | Database migration path. 51 | |-------------------------------------------------------------------- 52 | | 53 | | Here is where you can register your migrations path to migrate 54 | | the schema via migrate artisan command. 55 | | 56 | */ 57 | 58 | 'database' => null, 59 | 60 | /* 61 | |------------------------------------------------------------------- 62 | | Default route file 63 | |------------------------------------------------------------------- 64 | | 65 | | Here is where you can register your route file. 66 | | 67 | */ 68 | 69 | 'routes' => base_path('routes/web.php'), 70 | 71 | /* 72 | |-------------------------------------------------------------------- 73 | | Default package namespace and loaders 74 | |-------------------------------------------------------------------- 75 | | 76 | | By default scaffold-interface interact with your app without 77 | | specify any namespace. otherwise, if there is a module or a package 78 | | that you may want scaffold-interface interact with, you must define 79 | | namespaces. 80 | | 81 | */ 82 | 83 | 'controllerNameSpace' => 'App\\Http\\Controllers', 84 | 85 | 'modelNameSpace' => 'App', 86 | 87 | /* 88 | |------------------------------------------------------------------- 89 | | Views loader 90 | |------------------------------------------------------------------- 91 | | 92 | | Here is where you can register your default views loader. 93 | | By default is null 94 | | 95 | */ 96 | 97 | 'loadViews' => null, 98 | 99 | /* 100 | |------------------------------------------------------------------- 101 | | Views prefix 102 | |------------------------------------------------------------------- 103 | | 104 | | Here is where you can register your default views prefix. 105 | | By default is null 106 | | 107 | */ 108 | 109 | 'prefixViews' => null, 110 | 111 | /* 112 | |------------------------------------------------------------------- 113 | | Route prefix 114 | |------------------------------------------------------------------- 115 | | 116 | | Here is where you can register your default views prefix. 117 | | By default is null 118 | | 119 | */ 120 | 121 | 'prefixRoutes' => null, 122 | 123 | ]; 124 | -------------------------------------------------------------------------------- /database/migrations/2015_10_31_162633_scaffoldinterfaces.php: -------------------------------------------------------------------------------- 1 | increments('id')->unsigned(); 17 | $table->String('package'); 18 | $table->String('migration'); 19 | $table->String('model'); 20 | $table->String('controller'); 21 | $table->String('views'); 22 | $table->String('tablename'); 23 | $table->timestamps(); 24 | }); 25 | Schema::create('relations', function (Blueprint $table) { 26 | $table->increments('id')->unsigned(); 27 | $table->integer('scaffoldinterface_id')->unsigned(); 28 | $table->String('to'); 29 | $table->String('having'); 30 | $table->foreign('scaffoldinterface_id')->references('id')->on('scaffoldinterfaces')->onDelete('cascade'); 31 | $table->timestamps(); 32 | }); 33 | } 34 | 35 | /** 36 | * Reverse the migrations. 37 | * 38 | * @return void 39 | */ 40 | public function down() 41 | { 42 | Schema::drop('relations'); 43 | Schema::drop('scaffoldinterfaces'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /resources/assets/css/scaffold-interface-css/main.css: -------------------------------------------------------------------------------- 1 | label { 2 | width: 100%; 3 | } 4 | 5 | .scaffoldv { 6 | border-radius: 3px; 7 | padding: 0 5px 0 5px; 8 | } 9 | 10 | .input-field label { 11 | font-size: 0.8rem; 12 | -webkit-transform: translateY(-140%); 13 | -moz-transform: translateY(-140%); 14 | -ms-transform: translateY(-140%); 15 | -o-transform: translateY(-140%); 16 | transform: translateY(-140%); 17 | } 18 | 19 | .pushDown { 20 | margin-top: 20px; 21 | } 22 | 23 | .pushlDown { 24 | margin-top: 5px; 25 | } 26 | -------------------------------------------------------------------------------- /resources/assets/js/scaffold-interface-js/customA.js: -------------------------------------------------------------------------------- 1 | $(document).on("click", ".viewEdit", function() { 2 | GETT($(this).data('link')); 3 | }) 4 | $(document).on("click", ".viewShow", function() { 5 | GETT($(this).data('link')); 6 | }) 7 | function GETT(dataLink) { 8 | $.ajax({ 9 | async: true, 10 | method: 'get', 11 | url: baseURL + dataLink, 12 | success: function(response) { 13 | window.location = response 14 | } 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /resources/assets/js/scaffold-interface-js/main.js: -------------------------------------------------------------------------------- 1 | //helper function 2 | function inArray(needle, haystack) { 3 | var length = haystack.length; 4 | for (var i = 0; i < length; i++) { 5 | if (haystack[i].onData == needle) return true; 6 | if (haystack[i].table == needle) return true; 7 | } 8 | return false; 9 | } 10 | // transitions and animations 11 | Vue.transition('fade', { 12 | enterClass: 'fadeInRight', 13 | leaveClass: 'fadeOutLeft' 14 | }); 15 | Vue.transition('actions', { 16 | enterClass: 'fadeInRight', 17 | leaveClass: 'zoomOutUp' 18 | }); 19 | var vm = new Vue({ 20 | el: 'body', 21 | data: { 22 | //Booleans 23 | show: false, 24 | submit: false, 25 | error: false, 26 | OneToManyBool: false, 27 | more: false, 28 | OpenClose: false, 29 | //error message 30 | errorMsg: '', 31 | // Type select 32 | select: ['String', 'date', 'longText', 'integer', 'biginteger', 'boolean', 'float'], 33 | selected: '0', 34 | // rows counts 35 | rows: 0, 36 | // your base Url 37 | baseUrl: baseURL, 38 | // Tables 39 | OneToMany: scaffoldList, 40 | attributes: [], 41 | OneToManyRows: 0, 42 | table: '', 43 | OneToManyData: [], 44 | }, 45 | methods: { 46 | // add row 47 | increment: function() { 48 | this.error = false; 49 | this.rows += 1; 50 | }, 51 | //delete row 52 | decrement: function() { 53 | if (this.rows == 0 && this.OneToManyRows == 0) { 54 | this.errorMsg = 'Can not remove the line!!' 55 | this.error = true; 56 | } else { 57 | if (this.OneToManyRows != 0) { 58 | this.OneToManyData.$remove(this.OneToManyRows); 59 | this.OneToManyRows -= 1; 60 | return; 61 | } 62 | this.rows -= 1; 63 | } 64 | }, 65 | // add relation 66 | addOneToMany: function() { 67 | this.OneToManyBool = true; 68 | if (this.OpenClose) { 69 | var onData = $('#on').val(); 70 | var table = $('#tbl').val(); 71 | if (!onData || inArray(table, this.OneToManyData)) { 72 | this.errorMsg = "Whoops, Error!!"; 73 | this.error = true 74 | return; 75 | } 76 | this.OneToManyData.push({ 77 | id: this.OneToManyRows, 78 | table: this.table, 79 | onData: onData 80 | }); 81 | this.OneToManyRows += 1; 82 | } 83 | this.error = false; 84 | }, 85 | // get attributes 86 | getAttr: function(index) { 87 | console.log(index); 88 | this.selected = $('#tbl').val(); 89 | console.log(this.baseUrl + '/scaffold/getAttributes/' + this.selected); 90 | $.getJSON(this.baseUrl + '/scaffold/getAttributes/' + this.selected, function(response) { 91 | this.attributes = response 92 | this.table = this.selected; 93 | this.OpenClose = true; 94 | }.bind(this)).error(function(response) { 95 | vm.errorMsg = 'Field not founds or the table does not migrated'; 96 | vm.error = true 97 | }); 98 | }, 99 | // switch 100 | lastStep: function() { 101 | this.submit = false; 102 | this.more = false; 103 | this.OneToManyBool = false; 104 | }, 105 | //switch 106 | lastOne: function() { 107 | this.submit = !this.submit; 108 | this.OneToManyBool = false; 109 | }, 110 | //romove relation 111 | removeRelation: function(item) { 112 | this.OneToManyData.$remove(item); 113 | } 114 | } 115 | }) 116 | -------------------------------------------------------------------------------- /resources/assets/js/scaffold-interface-js/main2.js: -------------------------------------------------------------------------------- 1 | 2 | // NOTE: this script is still development stage 3 | 4 | var vm = new Vue({ 5 | el: '#app', 6 | mounted () { 7 | axios.get(baseURL + '/scaffold/getTabels').then(function(response) { 8 | console.log(response) 9 | }).catch(function(error) { 10 | console.log(error) 11 | }) 12 | }, 13 | data () { 14 | return { 15 | hello: "Smart CRUD Generator For Laravel" 16 | } 17 | } 18 | }) -------------------------------------------------------------------------------- /resources/assets/js/scaffold-interface-js/social.js: -------------------------------------------------------------------------------- 1 | window.twttr = (function(d, s, id) { 2 | var js, fjs = d.getElementsByTagName(s)[0], 3 | t = window.twttr || {}; 4 | if (d.getElementById(id)) return t; 5 | js = d.createElement(s); 6 | js.id = id; 7 | js.src = "https://platform.twitter.com/widgets.js"; 8 | fjs.parentNode.insertBefore(js, fjs); 9 | t._e = []; 10 | t.ready = function(f) { 11 | t._e.push(f); 12 | }; 13 | return t; 14 | }(document, "script", "twitter-wjs")); 15 | -------------------------------------------------------------------------------- /resources/views/graph.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Graph 6 | 7 | 8 | 9 | 41 | 42 | 43 | 44 | 51 | 52 | 53 |
54 |
55 |

Models graph 56 |
57 | Back to the interface 58 | Dashboard

59 |
60 |
61 |
62 |
63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /resources/views/scaffold.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Smart CRUD GENERATOR v2 10 | 11 | 12 | 13 | 14 |
15 |
16 |
17 |
18 |
19 |
20 | Database 21 |
22 |
23 |
Tables
24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
NamePackageCreated atStateLinkDelete
@{{entity.tablename}}@{{entity.package}}@{{entity.created_at}}TBDLinkRollback
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | 55 |
56 |
57 |
58 | Create New Table 59 |
60 |
61 |
TBD
62 |
63 |
64 |
65 |
66 |
67 | 68 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /resources/views/scaffoldApp.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | The scaffold interface 11 | 12 | 13 |
14 |

A Smart CRUD Generator For Laravel

15 |
16 | 17 | device_hubMany To Many 18 | shareGraph 19 |
20 |
21 |
22 |

@{{errorMsg}}

23 |
24 | {{csrf_field()}} 25 | 26 | 27 | 33 | 34 | 35 | 39 | 43 | 44 | 45 | 51 | 57 | 58 | 59 | 67 | 73 | 74 | 75 | 76 | 80 | 84 | 87 | 88 | 89 | 95 | 101 | 102 |
28 |
29 | 30 | 31 |
32 |
36 | 37 | 38 | 40 | 41 | 42 |
46 |

47 | 48 | 49 |

50 |
52 |

53 | 54 | 55 |

56 |
60 |
61 | 65 |
66 |
68 |
69 | 70 | 71 |
72 |
77 | 78 |
@{{final.table}}
79 |
81 | 82 |
@{{final.onData}}
83 |
85 | delete 86 |
90 | 94 | 96 | 100 |
103 |
104 | 108 |
109 |
110 |
111 |
112 |
113 |
114 |

Actions

115 |
116 |
117 | addnew 118 | deleteremove 119 | arrow_forwardmore 120 |
121 | 126 |
127 |
128 |
129 | 130 |
131 |
132 |
You're working in {{config('amranidev.config.package')}}
133 |
134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | @foreach($scaffold as $value) 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | @endforeach 154 | 155 |
NamePackageCreated atStateLinkDelete
{{$value->tablename}}{{$value->package}}{{$value->created_at}}{{$toto = Schema::hasTable($value->tablename) ? 'Migrated' : 'Not migrated'}}sendrepeat
156 | {!! $scaffold->render() !!} 157 |
158 | Scaffold-interface dev-master

159 | 160 | 161 | 162 | 165 |

Created with love and free_breakfast by Amrani Houssain {{date("Y")}}

166 |
167 |
168 |
169 |
170 |
171 | 172 | 173 | 174 | 179 |
180 | 184 | 185 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 200 | 201 | -------------------------------------------------------------------------------- /resources/views/template/DeleteMessage/delete.blade.php: -------------------------------------------------------------------------------- 1 |
2 |

Whoops!!

3 |
Seems like you want to delete {{$table}} MVC files
4 |
Please rollback {{$table}} schema and try again!!
5 |
6 | -------------------------------------------------------------------------------- /resources/views/template/ManyToMany/migration.blade.php: -------------------------------------------------------------------------------- 1 | use Illuminate\Database\Schema\Blueprint; 2 | use Illuminate\Database\Migrations\Migration; 3 | 4 | class {{ucfirst($first)}}{{ucfirst($second)}} extends Migration 5 | { 6 | /** 7 | * Run the migrations. 8 | * 9 | * @return void 10 | */ 11 | public function up() 12 | { 13 | Schema::create('{{str_singular($first)}}_{{str_singular($second)}}',function (Blueprint $table){ 14 | $table->increments('id')->unique()->index()->unsigned(); 15 | $table->integer('{{str_singular($first)}}_id')->unsigned()->index(); 16 | $table->foreign('{{str_singular($first)}}_id')->references('id')->on('{{$first}}')->onDelete('cascade'); 17 | $table->integer('{{str_singular($second)}}_id')->unsigned()->index(); 18 | $table->foreign('{{str_singular($second)}}_id')->references('id')->on('{{$second}}')->onDelete('cascade'); 19 | /** 20 | * Type your addition here 21 | * 22 | */ 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::drop('{{str_singular($first)}}_{{str_singular($second)}}'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /resources/views/template/ManyToMany/model.blade.php: -------------------------------------------------------------------------------- 1 | /** 2 | * {{str_singular($model)}}. 3 | * 4 | * @return \Illuminate\Support\Collection; 5 | */ 6 | public function {{str_plural($model)}}() 7 | { 8 | return $this->belongsToMany('{{ config('amranidev.config.modelNameSpace') }}\{{ucfirst(str_singular($model))}}'); 9 | } 10 | 11 | /** 12 | * Assign a {{str_singular($model)}}. 13 | * 14 | * @param ${{str_singular($model)}} 15 | * @return mixed 16 | */ 17 | public function assign{{ucfirst(str_singular($model))}}(${{str_singular($model)}}) 18 | { 19 | return $this->{{str_plural($model)}}()->attach(${{str_singular($model)}}); 20 | } 21 | /** 22 | * Remove a {{str_singular($model)}}. 23 | * 24 | * @param ${{str_singular($model)}} 25 | * @return mixed 26 | */ 27 | public function remove{{ucfirst(str_singular($model))}}(${{str_singular($model)}}) 28 | { 29 | return $this->{{str_plural($model)}}()->detach(${{str_singular($model)}}); 30 | } 31 | -------------------------------------------------------------------------------- /resources/views/template/controller/controller.blade.php: -------------------------------------------------------------------------------- 1 | namespace {{config('amranidev.config.controllerNameSpace')}}; 2 | 3 | use Illuminate\Support\Facades\App; 4 | use Illuminate\Http\Request; 5 | use App\Http\Controllers\Controller; 6 | use {{config('amranidev.config.modelNameSpace')}}\{{ucfirst($parser->singular())}}; 7 | use Amranidev\Ajaxis\Ajaxis; 8 | use URL; 9 | @foreach($dataSystem->getForeignKeys() as $key) 10 | 11 | use {{config('amranidev.config.modelNameSpace')}}\{{ucfirst(str_singular($key))}}; 12 | 13 | @endforeach 14 | 15 | /** 16 | * Class {{ucfirst($parser->singular())}}Controller. 17 | * 18 | * @author The scaffold-interface created at {{date("Y-m-d h:i:sa")}} 19 | * @link https://github.com/amranidev/scaffold-interface 20 | */ 21 | class {{ucfirst($parser->singular())}}Controller extends Controller 22 | { 23 | /** 24 | * Display a listing of the resource. 25 | * 26 | * @return \Illuminate\Http\Response 27 | */ 28 | public function index() 29 | { 30 | $title = 'Index - {{$parser->singular()}}'; 31 | ${{$parser->plural()}} = {{ucfirst($parser->singular())}}::paginate(6); 32 | return view('@if(config('amranidev.config.loadViews')){{config('amranidev.config.loadViews')}}::@endif{{$parser->singular()}}.index',compact('{{$parser->plural()}}','title')); 33 | } 34 | 35 | /** 36 | * Show the form for creating a new resource. 37 | * 38 | * @return \Illuminate\Http\Response 39 | */ 40 | public function create() 41 | { 42 | $title = 'Create - {{$parser->singular()}}'; 43 | @foreach($dataSystem->getForeignKeys() as $key => $value) 44 | 45 | ${{str_plural($value)}} = {{ucfirst(str_singular($value))}}::all()->pluck('{{$dataSystem->getOnData()[$key]}}','id'); 46 | @endforeach 47 | 48 | return view('@if(config('amranidev.config.loadViews')){{config('amranidev.config.loadViews')}}::@endif @if(config('amranidev.config.prefixViews')){{config('amranidev.config.prefixViews')}}.@endif{{$parser->singular()}}.create'@if($dataSystem->getForeignKeys() != null),compact('title',@foreach($dataSystem->getForeignKeys() as $key => $value)'{{str_plural($value)}}' @if($value != last($dataSystem->getForeignKeys())),@endif @endforeach)@endif); 49 | } 50 | 51 | /** 52 | * Store a newly created resource in storage. 53 | * 54 | * @param \Illuminate\Http\Request $request 55 | * @return \Illuminate\Http\Response 56 | */ 57 | public function store(Request $request) 58 | { 59 | ${{$parser->singular()}} = new {{ucfirst($parser->singular())}}(); 60 | 61 | @foreach($dataSystem->dataScaffold('v') as $value) 62 | 63 | ${{$parser->singular()}}->{{$value}} = $request->{{$value}}; 64 | 65 | @endforeach 66 | 67 | @foreach($dataSystem->getForeignKeys() as $key) 68 | 69 | ${{$parser->singular()}}->{{lcfirst(str_singular($key))}}_id = $request->{{lcfirst(str_singular($key))}}_id; 70 | 71 | @endforeach 72 | 73 | ${{$parser->singular()}}->save(); 74 | 75 | $pusher = App::make('pusher'); 76 | 77 | //default pusher notification. 78 | //by default channel=test-channel,event=test-event 79 | //Here is a pusher notification example when you create a new resource in storage. 80 | //you can modify anything you want or use it wherever. 81 | $pusher->trigger('test-channel', 82 | 'test-event', 83 | ['message' => 'A new {{$parser->singular()}} has been created !!']); 84 | 85 | return redirect('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}'); 86 | } 87 | 88 | /** 89 | * Display the specified resource. 90 | * 91 | * @param \Illuminate\Http\Request $request 92 | * @param int $id 93 | * @return \Illuminate\Http\Response 94 | */ 95 | public function show($id,Request $request) 96 | { 97 | $title = 'Show - {{$parser->singular()}}'; 98 | 99 | if($request->ajax()) 100 | { 101 | return URL::to('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}/'.$id); 102 | } 103 | 104 | ${{$parser->singular()}} = {{ucfirst($parser->singular())}}::findOrfail($id); 105 | return view('@if(config('amranidev.config.loadViews')){{config('amranidev.config.loadViews')}}::@endif{{$parser->singular()}}.show',compact('title','{{$parser->singular()}}')); 106 | } 107 | 108 | /** 109 | * Show the form for editing the specified resource. 110 | * @param \Illuminate\Http\Request $request 111 | * @param int $id 112 | * @return \Illuminate\Http\Response 113 | */ 114 | public function edit($id,Request $request) 115 | { 116 | $title = 'Edit - {{$parser->singular()}}'; 117 | if($request->ajax()) 118 | { 119 | return URL::to('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}/'. $id . '/edit'); 120 | } 121 | 122 | @foreach($dataSystem->getForeignKeys() as $key => $value) 123 | 124 | ${{str_plural($value)}} = {{ucfirst(str_singular($value))}}::all()->pluck('{{$dataSystem->getOnData()[$key]}}','id'); 125 | 126 | @endforeach 127 | 128 | ${{$parser->singular()}} = {{ucfirst($parser->singular())}}::findOrfail($id); 129 | return view('@if(config('amranidev.config.loadViews')){{config('amranidev.config.loadViews')}}::@endif{{$parser->singular()}}.edit',compact('title','{{$parser->singular()}}' @if($dataSystem->getForeignKeys() != null),@foreach($dataSystem->getForeignKeys() as $key => $value)'{{str_plural($value)}}'@if($value != last($dataSystem->getForeignKeys())),@endif @endforeach) @else )@endif); 130 | } 131 | 132 | /** 133 | * Update the specified resource in storage. 134 | * 135 | * @param \Illuminate\Http\Request $request 136 | * @param int $id 137 | * @return \Illuminate\Http\Response 138 | */ 139 | public function update($id,Request $request) 140 | { 141 | ${{$parser->singular()}} = {{ucfirst($parser->singular())}}::findOrfail($id); 142 | @foreach($dataSystem->dataScaffold('v') as $value) 143 | 144 | ${{$parser->singular()}}->{{$value}} = $request->{{$value}}; 145 | @endforeach 146 | 147 | @foreach($dataSystem->getForeignKeys() as $key) 148 | 149 | ${{$parser->singular()}}->{{lcfirst(str_singular($key))}}_id = $request->{{lcfirst(str_singular($key))}}_id; 150 | 151 | @endforeach 152 | 153 | ${{$parser->singular()}}->save(); 154 | 155 | return redirect('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}'); 156 | } 157 | 158 | /** 159 | * Delete confirmation message by Ajaxis. 160 | * 161 | * @link https://github.com/amranidev/ajaxis 162 | * @param \Illuminate\Http\Request $request 163 | * @return String 164 | */ 165 | public function DeleteMsg($id,Request $request) 166 | { 167 | $msg = Ajaxis::{{$parser->getParse()}}Deleting('Warning!!','Would you like to remove This?','/{{$parser->singular()}}/'. $id . '/delete'); 168 | 169 | if($request->ajax()) 170 | { 171 | return $msg; 172 | } 173 | } 174 | 175 | /** 176 | * Remove the specified resource from storage. 177 | * 178 | * @param int $id 179 | * @return \Illuminate\Http\Response 180 | */ 181 | public function destroy($id) 182 | { 183 | ${{$parser->singular()}} = {{ucfirst($parser->singular())}}::findOrfail($id); 184 | ${{$parser->singular()}}->delete(); 185 | return URL::to('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}'); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /resources/views/template/migration/migration.blade.php: -------------------------------------------------------------------------------- 1 | use Illuminate\Database\Schema\Blueprint; 2 | use Illuminate\Database\Migrations\Migration; 3 | 4 | /** 5 | * Class {{ucfirst($parser->plural())}}. 6 | * 7 | * @author The scaffold-interface created at {{date("Y-m-d h:i:sa")}} 8 | * @link https://github.com/amranidev/scaffold-interface 9 | */ 10 | class {{studly_case(ucfirst($parser->plural()))}} extends Migration 11 | { 12 | /** 13 | * Run the migrations. 14 | * 15 | * @return void 16 | */ 17 | public function up() 18 | { 19 | Schema::create('{{$parser->plural()}}',function (Blueprint $table){ 20 | 21 | $table->increments('id'); 22 | 23 | @foreach($dataSystem->dataScaffold('v') as $attr) 24 | 25 | $table->{{$dataSystem->dataScaffold('migration')[$i]}}('{{$attr}}'); 26 | 27 | @endforeach 28 | 29 | /** 30 | * Foreignkeys section 31 | */ 32 | @foreach($dataSystem->getForeignKeys() as $key) 33 | 34 | $table->integer('{{lcfirst(str_singular($key))}}_id')->unsigned()->nullable(); 35 | $table->foreign('{{lcfirst(str_singular($key))}}_id')->references('id')->on('{{$key}}')->onDelete('cascade'); 36 | @endforeach 37 | 38 | @if($dataSystem->isTimestamps()) 39 | 40 | $table->timestamps(); 41 | @endif 42 | 43 | @if($dataSystem->isSoftdeletes()) 44 | 45 | $table->softDeletes(); 46 | @endif 47 | 48 | // type your addition here 49 | 50 | }); 51 | } 52 | 53 | /** 54 | * Reverse the migrations. 55 | * 56 | * @return void 57 | */ 58 | public function down() 59 | { 60 | Schema::drop('{{$parser->plural()}}'); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /resources/views/template/model/model.blade.php: -------------------------------------------------------------------------------- 1 | namespace {{config('amranidev.config.modelNameSpace')}}; 2 | 3 | use Illuminate\Database\Eloquent\Model; 4 | use Illuminate\Database\Eloquent\SoftDeletes; 5 | 6 | /** 7 | * Class {{ucfirst($parser->singular())}}. 8 | * 9 | * @author The scaffold-interface created at {{date("Y-m-d h:i:sa")}} 10 | * @link https://github.com/amranidev/scaffold-interface 11 | */ 12 | class {{ucfirst($parser->singular())}} extends Model 13 | { 14 | @if($dataSystem->isSoftdeletes()) 15 | 16 | use SoftDeletes; 17 | 18 | protected $dates = ['deleted_at']; 19 | @endif 20 | 21 | @if(!$dataSystem->isTimestamps()) 22 | 23 | public $timestamps = false; 24 | @endif 25 | 26 | protected $table = '{{$parser->plural()}}'; 27 | 28 | @foreach($dataSystem->getForeignKeys() as $key) 29 | 30 | public function {{lcfirst(str_singular($key))}}() 31 | { 32 | return $this->belongsTo('{{config('amranidev.config.modelNameSpace')}}\{{ucfirst(str_singular($key))}}','{{lcfirst(str_singular($key))}}_id'); 33 | } 34 | 35 | @endforeach 36 | 37 | } 38 | -------------------------------------------------------------------------------- /resources/views/template/routes.blade.php: -------------------------------------------------------------------------------- 1 | //{{$parser->singular()}} Routes 2 | Route::group(['middleware'=> 'web'],function(){ 3 | Route::resource('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}','@if(config('amranidev.config.controllerNameSpace'))\{{config('amranidev.config.controllerNameSpace')}}\@endif{{ucfirst($parser->singular())}}Controller'); 4 | Route::post('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}/{id}/update','@if(config('amranidev.config.controllerNameSpace'))\{{config('amranidev.config.controllerNameSpace')}}\@endif{{ucfirst($parser->singular())}}Controller@update'); 5 | Route::get('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}/{id}/delete','@if(config('amranidev.config.controllerNameSpace'))\{{config('amranidev.config.controllerNameSpace')}}\@endif{{ucfirst($parser->singular())}}Controller@destroy'); 6 | Route::get('@if(config('amranidev.config.prefixRoutes')){{config('amranidev.config.prefixRoutes')}}/@endif{{$parser->singular()}}/{id}/deleteMsg','@if(config('amranidev.config.controllerNameSpace'))\{{config('amranidev.config.controllerNameSpace')}}\@endif{{ucfirst($parser->singular())}}Controller@DeleteMsg'); 7 | }); 8 | -------------------------------------------------------------------------------- /resources/views/template/views/bootstrap/create.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.app') 2 | @@section('title','Create') 3 | @@section('content') 4 |
5 |

Create {{$parser->singular()}}

6 | {{$parser->upperCaseFirst()}} Index 7 |
8 |
9 | 10 | @foreach($dataSystem->dataScaffold('v') as $value) 11 |
12 | 13 | 14 |
15 | @endforeach 16 | @foreach($dataSystem->getForeignKeys() as $key) 17 |
18 | 19 | 24 |
25 | @endforeach 26 | 27 |
28 |
29 | @@endsection 30 | -------------------------------------------------------------------------------- /resources/views/template/views/bootstrap/edit.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.app') 2 | @@section('title','Edit') 3 | @@section('content') 4 |
5 |

Edit {{$parser->singular()}}

6 | {{$parser->upperCaseFirst()}} Index 7 |
8 |
9 | 10 | @foreach($dataSystem->dataScaffold('v') as $value) 11 |
12 | 13 | 14 |
15 | @endforeach 16 | @foreach($dataSystem->getForeignKeys() as $key) 17 |
18 | 19 | 24 |
25 | @endforeach 26 | 27 |
28 |
29 | @@endsection 30 | -------------------------------------------------------------------------------- /resources/views/template/views/bootstrap/index.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.app') 2 | @@section('title','Index') 3 | @@section('content') 4 |
5 |

{{ucfirst($parser->singular())}} Index

6 | New 7 |
8 | @if($dataSystem->getRelationAttributes() != null) 9 | 20 | @endif 21 |
22 | 23 | 24 | @foreach($dataSystem->dataScaffold('v') as $value) 25 | 26 | @endforeach 27 | @if($dataSystem->getRelationAttributes() != null) 28 | @foreach($dataSystem->getRelationAttributes() as $key => $value) 29 | @foreach($value as $key1 => $value1) 30 | 31 | @endforeach 32 | @endforeach 33 | @endif 34 | 35 | 36 | 37 | @@foreach(${{$parser->plural()}} as ${{lcfirst($parser->singular())}}) 38 | 39 | @foreach($dataSystem->dataScaffold('v') as $value) 40 | 41 | @endforeach 42 | @if($dataSystem->getRelationAttributes() != null) 43 | @foreach($dataSystem->getRelationAttributes() as $key=>$value) 44 | @foreach($value as $key1 => $value1) 45 | 46 | @endforeach 47 | @endforeach 48 | @endif 49 | 54 | 55 | @@endforeach 56 | 57 |
{{$value}}{{$value1}}actions
@{!!${{lcfirst($parser->singular())}}->{{$value}}!!}@{!!${{$parser->singular()}}->{{str_singular($key)}}->{{$value1}}!!} 50 | delete 51 | edit 52 | info 53 |
58 | @{!! ${{$parser->plural()}}->render() !!} 59 |
60 | @@endsection 61 | -------------------------------------------------------------------------------- /resources/views/template/views/bootstrap/show.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.app') 2 | @@section('title','Show') 3 | @@section('content') 4 |
5 |

Show {{$parser->singular()}}

6 |
7 | {{$parser->upperCaseFirst()}} Index 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | @foreach($dataSystem->dataScaffold('v') as $value) 16 | 17 | 20 | 21 | 22 | @endforeach 23 | @if($dataSystem->getRelationAttributes() != null) 24 | @foreach($dataSystem->getRelationAttributes() as $key=>$value) 25 | @foreach($value as $key1 => $value1) 26 | 27 | 30 | 31 | 32 | @endforeach 33 | @endforeach 34 | @endif 35 | 36 |
KeyValue
18 | {{$value}} 19 | @{!!${{$parser->singular()}}->{{$value}}!!}
28 | {{$value1}} : 29 | @{!!${{$parser->singular()}}->{{str_singular($key)}}->{{$value1}}!!}
37 |
38 | @@endsection 39 | -------------------------------------------------------------------------------- /resources/views/template/views/materialize/create.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.defaultMaterialize') 2 | @@section('title','Create') 3 | @@section('content') 4 |
5 |

Create {{$parser->singular()}}

6 |
7 | 8 |
9 |
10 |
11 | 12 | @foreach($dataSystem->dataScaffold('v') as $value) 13 |
14 | 15 | 16 |
17 | @endforeach 18 | @foreach($dataSystem->getForeignKeys() as $key) 19 |
20 | 25 | 26 |
27 | @endforeach 28 | 29 |
30 |
31 | @@endsection 32 | -------------------------------------------------------------------------------- /resources/views/template/views/materialize/edit.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.defaultMaterialize') 2 | @@section('title','Edit') 3 | @@section('content') 4 |
5 |

Edit {{$parser->singular()}}

6 |
7 | 8 |
9 |
10 |
11 | 12 | @foreach($dataSystem->dataScaffold('v') as $value) 13 |
14 | 15 | 16 |
17 | @endforeach 18 | @foreach($dataSystem->getForeignKeys() as $key) 19 |
20 | 25 | 26 |
27 | @endforeach 28 | 29 |
30 |
31 | @@endsection 32 | -------------------------------------------------------------------------------- /resources/views/template/views/materialize/index.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.defaultMaterialize') 2 | @@section('title','Index') 3 | @@section('content') 4 |
5 |

{{$parser->singular()}} Index

6 |
7 |
8 | 9 |
10 | @if($dataSystem->getRelationAttributes() != null) 11 | 16 | Associate 17 | @endif 18 |
19 | 20 | 21 | @foreach($dataSystem->dataScaffold('v') as $value) 22 | 23 | @endforeach 24 | @if($dataSystem->getRelationAttributes() != null) 25 | @foreach($dataSystem->getRelationAttributes() as $key => $value) 26 | @foreach($value as $key1 => $value1) 27 | 28 | @endforeach 29 | @endforeach 30 | @endif 31 | 32 | 33 | 34 | @@foreach(${{$parser->plural()}} as ${{lcfirst($parser->singular())}}) 35 | 36 | @foreach($dataSystem->dataScaffold('v') as $value) 37 | 38 | @endforeach 39 | @if($dataSystem->getRelationAttributes() != null) 40 | @foreach($dataSystem->getRelationAttributes() as $key=>$value) 41 | @foreach($value as $key1 => $value1) 42 | 43 | @endforeach 44 | @endforeach 45 | @endif 46 | 53 | 54 | @@endforeach 55 | 56 |
{{$value}}{{$value1}}actions
@{!!${{lcfirst($parser->singular())}}->{{$value}}!!}@{!!${{$parser->singular()}}->{{str_singular($key)}}->{{$value1}}!!} 47 |
48 | delete 49 | edit 50 | info 51 |
52 |
57 | @{!! ${{$parser->plural()}}->render() !!} 58 |
59 | @@endsection 60 | -------------------------------------------------------------------------------- /resources/views/template/views/materialize/show.blade.php: -------------------------------------------------------------------------------- 1 | @@extends('scaffold-interface.layouts.defaultMaterialize') 2 | @@section('title','Show') 3 | @@section('content') 4 |
5 |

Show {{$parser->singular()}}

6 |
7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | @foreach($dataSystem->dataScaffold('v') as $value) 16 | 17 | 20 | 21 | 22 | @endforeach 23 | @if($dataSystem->getRelationAttributes() != null) 24 | @foreach($dataSystem->getRelationAttributes() as $key=>$value) 25 | @foreach($value as $key1 => $value1) 26 | 27 | 30 | 31 | 32 | @endforeach 33 | @endforeach 34 | @endif 35 | 36 |
KeyValue
18 | {{$value}} : 19 | @{!!${{$parser->singular()}}->{{$value}}!!}
28 | {{$value1}} : 29 | @{!!${{$parser->singular()}}->{{str_singular($key)}}->{{$value1}}!!}
37 |
38 | @@endsection 39 | -------------------------------------------------------------------------------- /src/Attribute.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class Attribute 13 | { 14 | /** 15 | * Table name. 16 | * 17 | * @var string 18 | */ 19 | private $table; 20 | 21 | /** 22 | * Excluded columns. 23 | * 24 | * @var array 25 | */ 26 | private $exclude = ['id', 'password', 'remember_token', 'created_at', 'updated_at', 'deleted_at']; 27 | 28 | /** 29 | * Create new attribute instance. 30 | * 31 | * @param $table 32 | */ 33 | public function __construct($table) 34 | { 35 | $this->table = $table; 36 | } 37 | 38 | /** 39 | * Get attributes from an existing table. 40 | * 41 | * @return array 42 | */ 43 | public function getAttributes() 44 | { 45 | return collect(Schema::getColumnListing($this->table))->filter(function ($column) { 46 | return !in_array($column, $this->exclude); 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Datasystem/Database/Database.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | abstract class Database implements DatabaseContractInterface 13 | { 14 | /** 15 | * table names to be skipped in the result. 16 | * 17 | * @var array 18 | */ 19 | protected $skips = [ 20 | 'migrations', 21 | 'scaffoldinterfaces', 22 | 'password_resets', 23 | ]; 24 | 25 | /** 26 | * retrieve table names from database. 27 | * 28 | * @return \Illuminate\Support\Collection 29 | */ 30 | public function tableNames() 31 | { 32 | return collect(DB::select($this->getQuery())) 33 | ->pluck('name')->reject(function ($name) { 34 | return $this->skips()->contains($name); 35 | }); 36 | } 37 | 38 | /** 39 | * Retrieve the database query for querying all tables. 40 | * 41 | * @return string 42 | */ 43 | abstract public function getQuery(); 44 | 45 | /** 46 | * Table names to be skipped in the result. 47 | * 48 | * @return \Illuminate\Support\Collection 49 | */ 50 | public function skips() 51 | { 52 | return collect($this->skips)->merge($this->skipNames()); 53 | } 54 | 55 | /** 56 | * Table names to be skipped in the result. 57 | * 58 | * @return \Illuminate\Support\Collection 59 | */ 60 | abstract public function skipNames(); 61 | } 62 | -------------------------------------------------------------------------------- /src/Datasystem/Database/DatabaseContractInterface.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | interface DatabaseContractInterface 11 | { 12 | /** 13 | * retrieve table names from database. 14 | * 15 | * @return \Illuminate\Support\Collection 16 | */ 17 | public function tableNames(); 18 | } 19 | -------------------------------------------------------------------------------- /src/Datasystem/Database/DatabaseManager.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class DatabaseManager 11 | { 12 | /** 13 | * Database holder. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\DataSystem\DatabaseContract 16 | */ 17 | protected $database; 18 | 19 | /** 20 | * Excluded tables. 21 | * 22 | * @var array 23 | */ 24 | protected $exclude = ['relations', 'role_has_permissions', 'model_has_roles', 'model_has_permissions']; 25 | 26 | public function __construct(DatabaseContractInterface $database) 27 | { 28 | $this->database = $database; 29 | } 30 | 31 | /** 32 | * New instance based on app's database driver. 33 | * 34 | * @return self 35 | */ 36 | public static function make() 37 | { 38 | $class = str_replace( 39 | 'DatabaseManager', 40 | ucfirst(config('database.default')).'Database', 41 | self::class 42 | ); 43 | 44 | try { 45 | return new self(new $class()); 46 | } catch (\Exception $e) { 47 | return new self(new MysqlDatabase()); 48 | } 49 | } 50 | 51 | /** 52 | * Retrieve table names from database. 53 | * 54 | * @return \Illuminate\Support\Collection 55 | */ 56 | public static function tableNames() 57 | { 58 | return self::make()->getTablesNames(); 59 | } 60 | 61 | /** 62 | * Get all tables names. 63 | * 64 | * @return \Illuminate\Support\Collection 65 | */ 66 | public function getTablesNames() 67 | { 68 | return $this->database->tableNames()->filter(function ($name) { 69 | return !in_array($name, $this->exclude); 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Datasystem/Database/MysqlDatabase.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class MysqlDatabase extends Database 13 | { 14 | public function tableNames() 15 | { 16 | return collect(DB::select($this->getQuery()))->pluck('Tables_in_'.env('DB_DATABASE'))->reject(function ($name) { 17 | return $this->skips()->contains($name); 18 | }); 19 | } 20 | 21 | /** 22 | * Mysql query. 23 | * 24 | * @return string 25 | */ 26 | public function getQuery() 27 | { 28 | return 'SHOW TABLES'; 29 | } 30 | 31 | /** 32 | * Skip unused schemas. 33 | * 34 | * @return \Illuminate\Support\Collection 35 | */ 36 | public function skipNames() 37 | { 38 | return collect([]); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Datasystem/Database/PgsqlDatabase.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class PgsqlDatabase extends Database 13 | { 14 | /** 15 | * retrieve table names from database. 16 | * 17 | * @return \Illuminate\Support\Collection 18 | */ 19 | public function tableNames() 20 | { 21 | return collect(DB::select($this->getQuery())) 22 | ->pluck('tablename')->reject(function ($name) { 23 | return $this->skips()->contains($name); 24 | }); 25 | } 26 | 27 | /** 28 | * postgres query. 29 | * 30 | * @return string 31 | */ 32 | public function getQuery() 33 | { 34 | return "SELECT * FROM pg_catalog.pg_tables WHERE 35 | schemaname != 'pg_catalog' AND schemaname != 'information_schema'"; 36 | } 37 | 38 | /** 39 | * skip unused schemas. 40 | * 41 | * @return \Illuminate\Support\Collection 42 | */ 43 | public function skipNames() 44 | { 45 | return collect([]); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Datasystem/Database/SqliteDatabase.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class SqliteDatabase extends Database 11 | { 12 | /** 13 | * sqlite query. 14 | * 15 | * @return string 16 | */ 17 | public function getQuery() 18 | { 19 | return "SELECT name FROM sqlite_master WHERE type='table'"; 20 | } 21 | 22 | /** 23 | * skip unused schemas. 24 | * 25 | * @return \Illuminate\Support\Collection 26 | */ 27 | public function skipNames() 28 | { 29 | return collect([ 30 | 'sqlite_sequence', 31 | ]); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Datasystem/Datasystem.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class Datasystem 14 | { 15 | /** 16 | * Main interface request. 17 | * 18 | * @var array 19 | */ 20 | private $data; 21 | 22 | /** 23 | * on data specification. 24 | * 25 | * @var array 26 | */ 27 | private $onData; 28 | 29 | /** 30 | * ForeignKeys and relations. 31 | * 32 | * @var array 33 | */ 34 | private $foreignKeys; 35 | 36 | /** 37 | * Relational columns. 38 | * 39 | * @var array 40 | */ 41 | private $relationAttributes; 42 | 43 | /** 44 | * Create a new DataSystem instance. 45 | * 46 | * @param array $request 47 | * 48 | * @return void 49 | */ 50 | public function __construct($request) 51 | { 52 | // unset TableName 53 | unset($request['TableName']); 54 | 55 | // unset template 56 | unset($request['template']); 57 | 58 | $this->data = $request; 59 | 60 | $this->relationData(); 61 | 62 | $this->getAttributes(); 63 | } 64 | 65 | /** 66 | * Deduce relational arttributes. 67 | * 68 | * @return void 69 | */ 70 | private function getAttributes() 71 | { 72 | collect($this->foreignKeys)->each(function ($key, $value) { 73 | $Schema = collect(Schema::getColumnListing($key)); 74 | $Schema = $Schema->reject(function ($value, $key) { 75 | return str_contains($value, 'id'); 76 | }); 77 | $this->relationAttributes[$key] = $Schema->toArray(); 78 | }); 79 | } 80 | 81 | /** 82 | * Deduce onData and foreingKeys. 83 | * 84 | * @return void 85 | */ 86 | private function relationData() 87 | { 88 | $onData = collect($this->data)->reject(function ($value, $key) { 89 | return !str_contains($key, 'on'); 90 | }); 91 | 92 | $foreignKeys = collect($this->data)->reject(function ($value, $key) { 93 | return !str_contains($key, 'tbl'); 94 | }); 95 | 96 | $this->onData = array_values($onData->toArray()); 97 | 98 | $this->foreignKeys = array_values($foreignKeys->toArray()); 99 | } 100 | 101 | /** 102 | * Data for migration and views. 103 | * 104 | * @param string specification 105 | * 106 | * @return array 107 | */ 108 | public function dataScaffold($spec = null) 109 | { 110 | $data = collect($this->data)->reject(function ($value, $key) use ($spec) { 111 | if ($spec == 'migration') { 112 | return !str_contains($key, 'opt'); 113 | } 114 | 115 | return !str_contains($key, 'atr'); 116 | }); 117 | 118 | return array_values($data->toArray()); 119 | } 120 | 121 | /** 122 | * Get foreignKeys. 123 | * 124 | * @return array 125 | */ 126 | public function getForeignKeys() 127 | { 128 | return $this->foreignKeys; 129 | } 130 | 131 | /** 132 | * Get relational attributes. 133 | * 134 | * @return array 135 | */ 136 | public function getRelationAttributes() 137 | { 138 | return $this->relationAttributes; 139 | } 140 | 141 | /** 142 | * Check timestamps. 143 | * 144 | * @return bool 145 | */ 146 | public function isTimestamps() 147 | { 148 | return array_key_exists('timestamps', $this->data) ? true : false; 149 | } 150 | 151 | /** 152 | * Check SoftDeletes. 153 | * 154 | * @return bool 155 | */ 156 | public function isSoftdeletes() 157 | { 158 | return array_key_exists('softdeletes', $this->data) ? true : false; 159 | } 160 | 161 | /** 162 | * Get onData. 163 | * 164 | * @return string 165 | */ 166 | public function getOnData() 167 | { 168 | return $this->onData; 169 | } 170 | 171 | /** 172 | * get request data. 173 | * 174 | * @return string 175 | */ 176 | public function getData() 177 | { 178 | return $this->data; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/Events/DeleteCrud.php: -------------------------------------------------------------------------------- 1 | scaffold = $scaffold; 29 | } 30 | 31 | /** 32 | * Get the channels the event should broadcast on. 33 | * 34 | * @return \Illuminate\Broadcasting\Channel|array 35 | */ 36 | public function broadcastOn() 37 | { 38 | return new PrivateChannel('channel-name'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Filesystem/FileAlreadyExists.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Filesystem 11 | { 12 | /** 13 | * Make a file. 14 | * 15 | * @param $file 16 | * @param $content 17 | * 18 | * @throws FileAlreadyExists 19 | * 20 | * @return int 21 | */ 22 | public function make($file, $content) 23 | { 24 | if ($this->exists($file)) { 25 | throw new FileAlreadyExists(); 26 | } 27 | 28 | return file_put_contents($file, $content); 29 | } 30 | 31 | /** 32 | * Determine if file is already exists. 33 | * 34 | * @param $file 35 | * 36 | * @return bool 37 | */ 38 | public function exists($file) 39 | { 40 | return file_exists($file); 41 | } 42 | 43 | /** 44 | * Make directory. 45 | * 46 | * @param string $path 47 | * 48 | * @return void 49 | */ 50 | public function makeDir($path) 51 | { 52 | if (is_dir($path)) { 53 | throw new FileAlreadyExists(); 54 | } 55 | mkdir($path, 0777, true); 56 | } 57 | 58 | /** 59 | * File append. 60 | * 61 | * @param strign $path 62 | * @param string $content 63 | * 64 | * @return int 65 | */ 66 | public function append($path, $content) 67 | { 68 | return file_put_contents($path, $content, FILE_APPEND | LOCK_EX); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Filesystem/Path.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Path 11 | { 12 | /** 13 | * The Parser instance. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\Parsers\Parser 16 | */ 17 | private $parser; 18 | 19 | /** 20 | * Migration file path. 21 | * 22 | * @var string 23 | */ 24 | public $migrationPath; 25 | 26 | /** 27 | * Create new Paths instance. 28 | * 29 | * @return void 30 | */ 31 | public function __construct() 32 | { 33 | $this->parser = app()->make('Parser'); 34 | 35 | $this->migrationPath = $this->MigrationPath(); 36 | } 37 | 38 | /** 39 | * Get model file path. 40 | * 41 | * @return string 42 | */ 43 | public function modelPath() 44 | { 45 | return config('amranidev.config.model').'/'.ucfirst($this->parser->singular()).'.php'; 46 | } 47 | 48 | /** 49 | * Get migration file path. 50 | * 51 | * @return string 52 | */ 53 | private function migrationPath() 54 | { 55 | $FileName = date('Y').'_'.date('m').'_'.date('d').'_'.date('his').'_'.$this->parser->plural().'.php'; 56 | 57 | return config('amranidev.config.migration').'/'.$FileName; 58 | } 59 | 60 | /** 61 | * Get controller file path. 62 | * 63 | * @return string 64 | */ 65 | public function controllerPath() 66 | { 67 | $FileName = ucfirst($this->parser->singular()).'Controller.php'; 68 | 69 | return config('amranidev.config.controller').'/'.$FileName; 70 | } 71 | 72 | /** 73 | * Get index file path. 74 | * 75 | * @return string 76 | */ 77 | public function indexPath() 78 | { 79 | return config('amranidev.config.views').'/'.$this->parser->singular().'/'.'index.blade.php'; 80 | } 81 | 82 | /** 83 | * Get create file path. 84 | * 85 | * @return string 86 | */ 87 | public function createPath() 88 | { 89 | return config('amranidev.config.views').'/'.$this->parser->singular().'/'.'create.blade.php'; 90 | } 91 | 92 | /** 93 | * Get show file path. 94 | * 95 | * @return string 96 | */ 97 | public function showPath() 98 | { 99 | return config('amranidev.config.views').'/'.$this->parser->singular().'/'.'show.blade.php'; 100 | } 101 | 102 | /** 103 | * Get edit file path. 104 | * 105 | * @return string 106 | */ 107 | public function editPath() 108 | { 109 | return config('amranidev.config.views').'/'.$this->parser->singular().'/'.'edit.blade.php'; 110 | } 111 | 112 | /** 113 | * Get route file path. 114 | * 115 | * @return string 116 | */ 117 | public function routePath() 118 | { 119 | return config('amranidev.config.routes'); 120 | } 121 | 122 | /** 123 | * Get views directory path. 124 | * 125 | * @return string 126 | */ 127 | public function dirPath() 128 | { 129 | return config('amranidev.config.views').'/'.$this->parser->singular(); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/Generators/ControllerGenerate.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class ControllerGenerate implements GeneratorInterface 11 | { 12 | /** 13 | * The DataSystem instance. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\Datasystem\Datasystem 16 | */ 17 | private $dataSystem; 18 | 19 | /** 20 | * The Parser instance. 21 | * 22 | * @var \Amranidev\ScaffoldInterface\Parsers\Parser 23 | */ 24 | private $parser; 25 | 26 | /** 27 | * Create new ControllerGenerate instance. 28 | * 29 | * @return void 30 | */ 31 | public function __construct() 32 | { 33 | $this->dataSystem = app()->make('Datasystem'); 34 | $this->parser = app()->make('Parser'); 35 | } 36 | 37 | /** 38 | * Compile controller template. 39 | * 40 | * @return string 41 | */ 42 | public function generate() 43 | { 44 | return " $this->parser, 'dataSystem' => $this->dataSystem])->render(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Generators/Generator.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class Generator extends Filesystem 13 | { 14 | /** 15 | * The ViewGenerate instance. 16 | * 17 | * @var \Amranidev\ScaffoldInterface\Generators\ViewGenerate 18 | */ 19 | private $view; 20 | 21 | /** 22 | * The ViewGenerate instance. 23 | * 24 | * @var \Amranidev\ScaffoldInterface\Generators\ModelGenerate 25 | */ 26 | private $model; 27 | 28 | /** 29 | * The ViewGenerate instance. 30 | * 31 | * @var \Amranidev\ScaffoldInterface\Generators\MigrationGenerate 32 | */ 33 | private $migration; 34 | 35 | /** 36 | * The ViewGenerate instance. 37 | * 38 | * @var \Amranidev\ScaffoldInterface\Generators\ControllerGenerate 39 | */ 40 | private $controller; 41 | 42 | /** 43 | * The ViewGenerate instance. 44 | * 45 | * @var \Amranidev\ScaffoldInterface\Generators\RouteGenerate 46 | */ 47 | private $route; 48 | 49 | /** 50 | * The ViewGenerate instance. 51 | * 52 | * @var \Amranidev\ScaffoldInterface\Filesystem\Path 53 | */ 54 | private $paths; 55 | 56 | /** 57 | * Create new Generator instance. 58 | * 59 | * @return void 60 | */ 61 | public function __construct() 62 | { 63 | $this->view = app()->make('ViewGenerate'); 64 | $this->model = app()->make('ModelGenerate'); 65 | $this->migration = app()->make('MigrationGenerate'); 66 | $this->controller = app()->make('ControllerGenerate'); 67 | $this->route = app()->make('RouteGenerate'); 68 | $this->paths = app()->make('Path'); 69 | } 70 | 71 | /** 72 | * Generate views. 73 | * 74 | * @return void 75 | */ 76 | public function views() 77 | { 78 | $this->make($this->paths->indexPath(), $this->view->generate()->index); 79 | $this->make($this->paths->createPath(), $this->view->generate()->create); 80 | $this->make($this->paths->showPath(), $this->view->generate()->show); 81 | $this->make($this->paths->editPath(), $this->view->generate()->edit); 82 | } 83 | 84 | /** 85 | * Generate views directory. 86 | * 87 | * @return void 88 | */ 89 | public function dir() 90 | { 91 | $this->makeDir($this->paths->dirPath()); 92 | } 93 | 94 | /** 95 | * Generate Model. 96 | * 97 | * @return void 98 | */ 99 | public function model() 100 | { 101 | $this->make($this->paths->modelPath(), $this->model->generate()); 102 | } 103 | 104 | /** 105 | * Generate Migration. 106 | * 107 | * @return void 108 | */ 109 | public function migration() 110 | { 111 | $this->make($this->paths->migrationPath, $this->migration->generate()); 112 | } 113 | 114 | /** 115 | * Generate Controller. 116 | * 117 | * @return void 118 | */ 119 | public function controller() 120 | { 121 | $this->make($this->paths->controllerPath(), $this->controller->generate()); 122 | } 123 | 124 | /** 125 | * Generate route. 126 | * 127 | * @return void 128 | */ 129 | public function route() 130 | { 131 | $this->append($this->paths->routePath(), $this->route->generate()); 132 | } 133 | 134 | /** 135 | * Get model generator instance. 136 | * 137 | * @return \Amranidev\ScaffoldInterface\Generators\ModelGenerate 138 | */ 139 | public function getModel() 140 | { 141 | return $this->model; 142 | } 143 | 144 | /** 145 | * Get migration generator instance. 146 | * 147 | * @return \Amranidev\ScaffoldInterface\Generators\MigrationGenerate 148 | */ 149 | public function getMigration() 150 | { 151 | return $this->migration; 152 | } 153 | 154 | /** 155 | * Get view generator instance. 156 | * 157 | * @return \Amranidev\ScaffoldInterface\Generators\ViewGenerate 158 | */ 159 | public function getView() 160 | { 161 | return $this->view; 162 | } 163 | 164 | /** 165 | * Get controller generator instance. 166 | * 167 | * @return \Amranidev\ScaffoldInterface\Generators\ControllerGenerate 168 | */ 169 | public function getController() 170 | { 171 | return $this->controller; 172 | } 173 | 174 | /** 175 | * get route. 176 | * 177 | * @return \Amranidev\ScaffoldInterface\Generators\RouteGenerate 178 | */ 179 | public function getRoute() 180 | { 181 | return $this->route; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/Generators/GeneratorInterface.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class MigrationGenerate implements GeneratorInterface 11 | { 12 | /** 13 | * The DataSystem instance. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\Datasystem\Datasystem 16 | */ 17 | private $dataSystem; 18 | 19 | /** 20 | * The Parser instance. 21 | * 22 | * @var \Amranidev\ScaffoldInterface\Parsers\Parser 23 | */ 24 | private $parser; 25 | 26 | /** 27 | * Create New MigrationGenerate instance. 28 | * 29 | * @return void 30 | */ 31 | public function __construct() 32 | { 33 | $this->dataSystem = app()->make('Datasystem'); 34 | $this->parser = app()->make('Parser'); 35 | } 36 | 37 | /** 38 | * Compile migration template. 39 | * 40 | * @return string 41 | */ 42 | public function generate() 43 | { 44 | return " $this->parser, 'dataSystem' => $this->dataSystem])->render(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Generators/ModelGenerate.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class ModelGenerate implements GeneratorInterface 11 | { 12 | /** 13 | * The DataSystem instance. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\Datasystem\Datasystem 16 | */ 17 | private $dataSystem; 18 | 19 | /** 20 | * The Parser instance. 21 | * 22 | * @var \Amranidev\ScaffoldInterface\Parsers\Parser 23 | */ 24 | private $parser; 25 | 26 | /** 27 | * Create new ModelGenerate instance. 28 | * 29 | * @return void 30 | */ 31 | public function __construct() 32 | { 33 | $this->dataSystem = app()->make('Datasystem'); 34 | $this->parser = app()->make('Parser'); 35 | } 36 | 37 | /** 38 | * Compile model template. 39 | * 40 | * @return string 41 | */ 42 | public function generate() 43 | { 44 | return " $this->parser, 'dataSystem' => $this->dataSystem])->render(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Generators/RouteGenerate.php: -------------------------------------------------------------------------------- 1 | parser = app()->make('Parser'); 27 | } 28 | 29 | /** 30 | * Compile route template. 31 | * 32 | * @return string 33 | */ 34 | public function generate() 35 | { 36 | return "\n".view('scaffold-interface::template.routes', ['parser' => $this->parser])->render(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Generators/ViewGenerate.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class ViewGenerate implements GeneratorInterface 11 | { 12 | /** 13 | * The DataSystem instance. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\Datasystem\Datasystem 16 | */ 17 | private $dataSystem; 18 | 19 | /** 20 | * The NamesGenerate instance. 21 | * 22 | * @var \Amranidev\ScaffoldInterface\Parsers\Parser 23 | */ 24 | private $parser; 25 | 26 | /** 27 | * The Indenter instance. 28 | * 29 | * @var \Gajus\Dindent\Indenter 30 | */ 31 | private $indenter; 32 | 33 | /** 34 | * Views. 35 | * 36 | * @var array 37 | */ 38 | private $views = ['index', 'create', 'edit', 'show']; 39 | 40 | /** 41 | * Create new ViewGenerate instance. 42 | * 43 | * @param $data Array 44 | * @param NamesGenerate 45 | * 46 | * @return void 47 | */ 48 | public function __construct() 49 | { 50 | $this->dataSystem = app()->make('Datasystem'); 51 | $this->parser = app()->make('Parser'); 52 | $this->indenter = app()->make('Indenter'); 53 | } 54 | 55 | /** 56 | * Generate View. 57 | * 58 | * @param string $view 59 | * 60 | * @return string 61 | */ 62 | private function generateView($view) 63 | { 64 | return $this->indenter 65 | ->indent(view('scaffold-interface::template.views.'.$this->parser->getTemplate().'.'.$view, 66 | ['parser' => $this->parser, 'dataSystem' => $this->dataSystem])->render()); 67 | } 68 | 69 | /** 70 | * Generate Views. 71 | * 72 | * @return mixed 73 | */ 74 | public function generate() 75 | { 76 | $views = new \StdClass(); 77 | 78 | foreach ($this->views as $view) { 79 | $views->{$view} = $this->generateView($view); 80 | } 81 | 82 | return $views; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Http/Controllers/GuiController.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class GuiController extends AppController 24 | { 25 | /** 26 | * Display a listing of the resource. 27 | * 28 | * @return \Illuminate\Http\Response 29 | */ 30 | public function index() 31 | { 32 | $scaffold = Scaffoldinterface::paginate(6); 33 | $scaffoldList = DatabaseManager::tableNames(); 34 | 35 | return view('scaffold-interface::scaffoldApp', compact('scaffold', 'scaffoldList')); 36 | } 37 | 38 | /** 39 | * Store a newly created resource in storage. 40 | * 41 | * @param \Illuminate\Http\Request $request 42 | * 43 | * @return \Illuminate\Http\Response 44 | */ 45 | public function store(Request $request) 46 | { 47 | app()->make('Request')->setRequest($request->toArray()); 48 | $scaffold = app()->make('Scaffold'); 49 | $relations = app()->make('Datasystem'); 50 | $scaffold->model()->views()->controller()->migration()->route(); 51 | $paths = app()->make('Path'); 52 | $names = app()->make('Parser'); 53 | 54 | $scaffoldInterface = Scaffoldinterface::create([ 55 | 'migration' => $paths->migrationPath, 56 | 'model' => $paths->modelPath(), 57 | 'controller' => $paths->controllerPath(), 58 | 'views' => $paths->dirPath(), 59 | 'tablename' => $names->plural(), 60 | 'package' => config('amranidev.config.package'), 61 | ]); 62 | 63 | if ($relations->getForeignKeys()) { 64 | foreach ($relations->getForeignKeys() as $foreignKey) { 65 | $record = DB::table('scaffoldinterfaces')->where('tablename', $foreignKey)->first(); 66 | Relation::create(['scaffoldinterface_id' => $scaffoldInterface->id, 67 | 'to' => $record->id, 68 | 'having' => Relation::ONE_TO_MANY, 69 | ]); 70 | } 71 | } 72 | 73 | Session::flash('status', 'Created Successfully '.$names->singular()); 74 | 75 | return redirect('scaffold'); 76 | } 77 | 78 | /** 79 | * Remove the specified resource from storage. 80 | * 81 | * @param int $id 82 | * 83 | * @return \Illuminate\Http\Response 84 | */ 85 | public function destroy($id) 86 | { 87 | $scaffoldInterface = Scaffoldinterface::FindOrFail($id); 88 | 89 | $scaffoldInterface->delete(); 90 | 91 | Session::flash('status', 'Deleted Successfully'); 92 | 93 | return URL::to('scaffold'); 94 | } 95 | 96 | /** 97 | * Delete confirmation message by ajaxis. 98 | * 99 | * @link https://github.com/amranidev/ajaxis 100 | * 101 | * @return \Illuminate\Http\Response 102 | */ 103 | public function deleteMsg($id) 104 | { 105 | $scaffold = Scaffoldinterface::FindOrFail($id); 106 | if (Schema::hasTable($scaffold->tablename)) { 107 | $table = $scaffold->tablename; 108 | 109 | return view('scaffold-interface::template.DeleteMessage.delete', compact('table'))->render(); 110 | } 111 | $msg = Ajaxis::Mtdeleting('Warning!!', "Would you like to delete {$scaffold->tablename} MVC files ??", '/scaffold/guirollback/'.$id); 112 | 113 | return $msg; 114 | } 115 | 116 | /** 117 | * Get attributes. 118 | * 119 | * @param string $table 120 | * 121 | * @return \Illuminate\Http\Response 122 | */ 123 | public function getResult($table, Request $request) 124 | { 125 | $attributes = new Attribute($table); 126 | if ($request->ajax()) { 127 | return response()->json($attributes->getAttributes(), 200); 128 | } 129 | } 130 | 131 | /** 132 | * Migrate schema. 133 | * 134 | * @return \Illuminate\Http\Response 135 | */ 136 | public function migrate() 137 | { 138 | try { 139 | Artisan::call('migrate', ['--path' => config('amranidev.config.database')]); 140 | exec('cd '.base_path().' && composer dump-autoload'); 141 | } catch (\Exception $e) { 142 | Session::flash('status', $e->getMessage()); 143 | 144 | return redirect('scaffold'); 145 | } 146 | $Msg = str_replace("\n", '', Artisan::output()); 147 | Session::flash('status', $Msg); 148 | 149 | return redirect('scaffold'); 150 | } 151 | 152 | /** 153 | * Rollback schema. 154 | * 155 | * @throws Exception 156 | * 157 | * @return \Illuminate\Http\Response 158 | */ 159 | public function rollback() 160 | { 161 | if (!Scaffoldinterface::all()->count()) { 162 | Session::flash('status', 'Nothing To Rollback'); 163 | 164 | return redirect('scaffold'); 165 | } 166 | 167 | try { 168 | Artisan::call('migrate:rollback'); 169 | } catch (\Exception $e) { 170 | return $e->getMessage(); 171 | } 172 | $Msg = str_replace("\n", '', Artisan::output()); 173 | Session::flash('status', $Msg); 174 | 175 | return redirect('scaffold'); 176 | } 177 | 178 | /** 179 | * ManyToMany form. 180 | * 181 | * @param \Illuminate\Http\Request 182 | * 183 | * @return \Illuminate\Http\Response 184 | */ 185 | public function manyToManyForm(Request $request) 186 | { 187 | $dummyData = DatabaseManager::tableNames(); 188 | $elements = Ajaxis::MtcreateFormModal([ 189 | ['type' => 'select', 'name' => 'table1', 'key' => 'table1', 'value' => $dummyData], 190 | ['type' => 'select', 'name' => 'table2', 'key' => 'table2', 'value' => $dummyData], ], '/scaffold/manyToMany', 'Many To Many'); 191 | 192 | return $elements; 193 | } 194 | 195 | /** 196 | * ManyToMany generate. 197 | * 198 | * @param \Illuminate\Http\Request 199 | * 200 | * @return \Illuminate\Http\Response 201 | */ 202 | public function manyToMany(Request $request) 203 | { 204 | if ($this->check($request->toArray())) { 205 | Session::flash('status', 'Error! could not be related'); 206 | 207 | return redirect('scaffold'); 208 | } 209 | $table1 = DB::table('scaffoldinterfaces')->where('tablename', $request->toArray()['table1'])->first(); 210 | $table2 = DB::table('scaffoldinterfaces')->where('tablename', $request->toArray()['table2'])->first(); 211 | $manytomany = new \Amranidev\ScaffoldInterface\ManyToMany\ManyToMany($request->except('_token')); 212 | $manytomany->burn(); 213 | 214 | Relation::create([ 215 | 'scaffoldinterface_id' => $table1->id, 216 | 'to' => $table2->id, 217 | 'having' => Relation::MANY_TO_MANY, 218 | ]); 219 | 220 | Session::flash('status', 'ManyToMany generated successfully'); 221 | 222 | return redirect('/scaffold'); 223 | } 224 | 225 | /** 226 | * Check ManyToMany request if it is available to be used. 227 | * 228 | * @param array $request 229 | * 230 | * @return mixed 231 | */ 232 | private function check(array $request) 233 | { 234 | return $request['table1'] == $request['table2'] ? true : false; 235 | } 236 | 237 | /** 238 | * Transform entities into a grahp. 239 | * 240 | * @return \Illuminate\Http\Response 241 | */ 242 | public function graph() 243 | { 244 | $nodes = Scaffoldinterface::all()->map(function (Scaffoldinterface $entity) { 245 | return ['id' => $entity->id, 'label' => $entity->tablename]; 246 | })->toJson(); 247 | 248 | $edges = Relation::all()->map(function (Relation $relation) { 249 | return ['from' => $relation->scaffoldinterface_id, 'to' => $relation->to, 'label' => $relation->having]; 250 | })->toJson(); 251 | 252 | return view('scaffold-interface::graph', compact('nodes', 'edges')); 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /src/Http/Controllers/ScaffoldInterfaceController.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | class ScaffoldMiddleware 14 | { 15 | /** 16 | * Handle an incoming request. 17 | * 18 | * @param \Illuminate\Http\Request $request 19 | * @param \Closure $next 20 | * 21 | * @return mixed 22 | */ 23 | public function handle(Request $request, Closure $next) 24 | { 25 | if ($request->segment(1) == 'scaffold') { 26 | 27 | // allowed env-s check 28 | $allowed = collect(config('amranidev.config.env')) 29 | ->contains(config('app.env')); 30 | 31 | if (!$allowed) { 32 | return redirect('/'); 33 | } 34 | } 35 | 36 | return $next($request); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Http/Request.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Request 11 | { 12 | /** 13 | * Request. 14 | * 15 | * @var array 16 | */ 17 | protected $request; 18 | 19 | /** 20 | * Set request. 21 | * 22 | * @param array $request 23 | * 24 | * @return void 25 | */ 26 | public function setRequest(array $request) 27 | { 28 | $this->request = $request; 29 | } 30 | 31 | /** 32 | * Get request. 33 | * 34 | * @return array $request 35 | */ 36 | public function getRequest() 37 | { 38 | return $this->request; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Http/routes.php: -------------------------------------------------------------------------------- 1 | 'web'], function () { 10 | Route::get('scaffold', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@index'); 11 | 12 | Route::post('scaffold/guipost', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@store'); 13 | 14 | Route::get('scaffold/guirollback/{id}', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@destroy'); 15 | 16 | Route::get('scaffold/guidelete/{id}', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@deleteMsg'); 17 | 18 | Route::get('scaffold/getAttributes/{table}', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@getResult'); 19 | 20 | Route::get('scaffold/migrate', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@migrate'); 21 | 22 | Route::get('scaffold/rollback', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@rollback'); 23 | 24 | Route::get('scaffold/manyToManyForm', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@manyToManyForm'); 25 | 26 | Route::post('scaffold/manyToMany', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@manyToMany'); 27 | 28 | Route::get('scaffold/graph', '\Amranidev\ScaffoldInterface\Http\Controllers\GuiController@graph'); 29 | }); 30 | 31 | /* 32 | |------------------------------------------------------------------------------ 33 | | Where user managment system routes (User-Role-Permission) 34 | |------------------------------------------------------------------------------ 35 | | 36 | */ 37 | Route::group(['middleware' => ['web', 'auth']], function () { 38 | // you can change anything you want. 39 | //Dashboard 40 | Route::get('scaffold-dashboard', '\App\Http\Controllers\ScaffoldInterface\AppController@dashboard'); 41 | 42 | //Users 43 | Route::get('scaffold-users', '\App\Http\Controllers\ScaffoldInterface\UserController@index'); 44 | Route::get('scaffold-users/edit/{user_id}', '\App\Http\Controllers\ScaffoldInterface\UserController@edit'); 45 | Route::post('scaffold-users/update', '\App\Http\Controllers\ScaffoldInterface\UserController@update'); 46 | Route::get('scaffold-users/create', '\App\Http\Controllers\ScaffoldInterface\UserController@create'); 47 | Route::post('scaffold-users/store', '\App\Http\Controllers\ScaffoldInterface\UserController@store'); 48 | Route::get('scaffold-users/delete/{user_id}', '\App\Http\Controllers\ScaffoldInterface\UserController@destroy'); 49 | Route::post('scaffold-users/addRole', '\App\Http\Controllers\ScaffoldInterface\UserController@addRole'); 50 | Route::post('scaffold-users/addPermission', '\App\Http\Controllers\ScaffoldInterface\UserController@addPermission'); 51 | Route::get('scaffold-users/removePermission/{permission}/{user_id}', '\App\Http\Controllers\ScaffoldInterface\UserController@revokePermission'); 52 | Route::get('scaffold-users/removeRole/{role}/{user_id}', '\App\Http\Controllers\ScaffoldInterface\UserController@revokeRole'); 53 | 54 | //Roles 55 | Route::get('scaffold-roles', '\App\Http\Controllers\ScaffoldInterface\RoleController@index'); 56 | Route::get('scaffold-roles/edit/{role_id}', '\App\Http\Controllers\ScaffoldInterface\RoleController@edit'); 57 | Route::post('scaffold-roles/update', '\App\Http\Controllers\ScaffoldInterface\RoleController@update'); 58 | Route::get('scaffold-roles/create', '\App\Http\Controllers\ScaffoldInterface\RoleController@create'); 59 | Route::post('scaffold-roles/store', '\App\Http\Controllers\ScaffoldInterface\RoleController@store'); 60 | Route::get('scaffold-roles/delete/{role_id}', '\App\Http\Controllers\ScaffoldInterface\RoleController@destroy'); 61 | 62 | //Permissions 63 | Route::get('scaffold-permissions', '\App\Http\Controllers\ScaffoldInterface\PermissionController@index'); 64 | Route::get('scaffold-permissions/edit/{role_id}', '\App\Http\Controllers\ScaffoldInterface\PermissionController@edit'); 65 | Route::post('scaffold-permissions/update', '\App\Http\Controllers\ScaffoldInterface\PermissionController@update'); 66 | Route::get('scaffold-permissions/create', '\App\Http\Controllers\ScaffoldInterface\PermissionController@create'); 67 | Route::post('scaffold-permissions/store', '\App\Http\Controllers\ScaffoldInterface\PermissionController@store'); 68 | Route::get('scaffold-permissions/delete/{role_id}', '\App\Http\Controllers\ScaffoldInterface\PermissionController@destroy'); 69 | }); 70 | -------------------------------------------------------------------------------- /src/Listeners/DeleteCrudFiles.php: -------------------------------------------------------------------------------- 1 | scaffold->migration); 29 | unlink($event->scaffold->model); 30 | unlink($event->scaffold->controller); 31 | unlink($event->scaffold->views.'/index.blade.php'); 32 | unlink($event->scaffold->views.'/create.blade.php'); 33 | unlink($event->scaffold->views.'/show.blade.php'); 34 | unlink($event->scaffold->views.'/edit.blade.php'); 35 | rmdir($event->scaffold->views); 36 | // clear Routes Resources. 37 | $this->clearRoutes(lcfirst(str_singular($event->scaffold->tablename))); 38 | } 39 | 40 | /** 41 | * Clear routes. 42 | * 43 | * @param string $remove 44 | * 45 | * @return mixed 46 | */ 47 | private function clearRoutes($remove) 48 | { 49 | $path = config('amranidev.config.routes'); 50 | $lines = file($path, FILE_IGNORE_NEW_LINES); 51 | 52 | foreach (array_filter($lines, function ($line) use ($remove) { 53 | return strstr($line, $remove); 54 | }) as $key => $line) { 55 | unset($lines[$key]); 56 | } 57 | 58 | return file_put_contents($path, implode("\n", array_values($lines))); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/ManyToMany/ManyToMany.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class ManyToMany extends Filesystem 13 | { 14 | /** 15 | * Request. 16 | * 17 | * @var array 18 | */ 19 | private $request; 20 | 21 | /** 22 | * Tables. 23 | * 24 | * @var array 25 | */ 26 | private $tables; 27 | 28 | /** 29 | * create new ManyToMany instance. 30 | * 31 | * @param array $request 32 | */ 33 | public function __construct(array $request) 34 | { 35 | $this->request = $request; 36 | $this->tables = $this->order(); 37 | } 38 | 39 | /** 40 | * Determine which table is ordered alphabetically. 41 | * 42 | * @return array $tables 43 | */ 44 | private function order() 45 | { 46 | $result = []; 47 | 48 | $data = $this->request; 49 | 50 | if ($data['table1'] > $data['table2']) { 51 | $result['first'] = $data['table2']; 52 | $result['second'] = $data['table1']; 53 | } else { 54 | $result['first'] = $data['table1']; 55 | $result['second'] = $data['table2']; 56 | } 57 | 58 | return $result; 59 | } 60 | 61 | /** 62 | * Add relationships methods to models. 63 | * 64 | * @return void 65 | */ 66 | private function model() 67 | { 68 | $this->relationship(config('amranidev.config.model').DIRECTORY_SEPARATOR.ucfirst(str_singular($this->tables['first'])).'.php', $this->tables['second']); 69 | $this->relationship(config('amranidev.config.model').DIRECTORY_SEPARATOR.ucfirst(str_singular($this->tables['second'])).'.php', $this->tables['first']); 70 | } 71 | 72 | /** 73 | * Make migration file. 74 | * 75 | * @return void 76 | */ 77 | private function migration() 78 | { 79 | $migrationContent = "tables)->render(); 80 | 81 | $migrationFileName = date('Y').'_'.date('m').'_'.date('d').'_'.date('his').'_'.ucfirst($this->tables['first']).ucfirst($this->tables['second']).'.php'; 82 | 83 | $this->make(config('amranidev.config.migration').'/'.$migrationFileName, $migrationContent); 84 | } 85 | 86 | /** 87 | * Generate relationships methods. 88 | * 89 | * @return bool 90 | */ 91 | private function relationship($path, $model) 92 | { 93 | $lines = file($path, FILE_IGNORE_NEW_LINES); 94 | $last = count($lines) - 1; 95 | unset($lines[$last]); 96 | $result = implode("\n", array_values($lines)); 97 | $model = view('scaffold-interface::template.ManyToMany.model', ['model' => $model])->render(); 98 | $result = $result."\n\n\t".$model."\n".'}'."\n"; 99 | 100 | return file_put_contents($path, $result); 101 | } 102 | 103 | /** 104 | * Generate ManyToMany. 105 | * 106 | * @return void 107 | */ 108 | public function burn() 109 | { 110 | $this->model(); 111 | $this->migration(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/Models/Relation.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Parser 11 | { 12 | /** 13 | * Parser data. 14 | * 15 | * @var array 16 | */ 17 | protected $data; 18 | 19 | /** 20 | * Create new Parser instance. 21 | * 22 | * @return void 23 | */ 24 | public function __construct($request) 25 | { 26 | $this->data = $request; 27 | } 28 | 29 | /** 30 | * Get the entity name singular. 31 | * 32 | * @return string 33 | */ 34 | public function singular() 35 | { 36 | return str_singular(str_slug($this->data['TableName'], '_')); 37 | } 38 | 39 | /** 40 | * Get the entity name plural. 41 | * 42 | * @return string 43 | */ 44 | public function plural() 45 | { 46 | return str_plural(str_slug($this->data['TableName'], '_')); 47 | } 48 | 49 | /** 50 | * Uppercase-ing the first charechter in the entity name. 51 | * 52 | * @return string 53 | */ 54 | public function upperCaseFirst() 55 | { 56 | return ucfirst($this->singular()); 57 | } 58 | 59 | /** 60 | * Get Template. 61 | * 62 | * @return string 63 | */ 64 | public function getTemplate() 65 | { 66 | return $this->data['template']; 67 | } 68 | 69 | /** 70 | * Parse template specification. 71 | * 72 | * @throws Exception 73 | * 74 | * @return string 75 | */ 76 | public function getParse() 77 | { 78 | if (starts_with($this->data['template'], 'boot')) { 79 | return 'Bt'; 80 | } else { 81 | return 'Mt'; 82 | } 83 | 84 | throw new \Exception('Template Error'); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Providers/ScaffoldInterfaceEventServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'Amranidev\ScaffoldInterface\Listeners\DeleteCrudFiles', 19 | ], 20 | ]; 21 | 22 | /** 23 | * Bootstrap the application events. 24 | * 25 | * @return void 26 | */ 27 | public function boot() 28 | { 29 | parent::boot(); 30 | 31 | Scaffoldinterface::deleted(function ($scaffold) { 32 | event(new DeleteCrud($scaffold)); 33 | }); 34 | } 35 | 36 | /** 37 | * Register the service provider. 38 | * 39 | * @return void 40 | */ 41 | public function register() 42 | { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Publishes/Controllers/ScaffoldInterface/AppController.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class AppController extends Controller 13 | { 14 | /** 15 | * Display a listing of the resource. 16 | * 17 | * @return \Illuminate\Http\Response 18 | */ 19 | public function dashboard() 20 | { 21 | $users = \App\User::all()->count(); 22 | $roles = \Spatie\Permission\Models\Role::all()->count(); 23 | $permissions = \Spatie\Permission\Models\Permission::all()->count(); 24 | $entities = \Amranidev\ScaffoldInterface\Models\Scaffoldinterface::all(); 25 | 26 | return view('scaffold-interface.dashboard.dashboard', compact('users', 'roles', 'permissions', 'entities')); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Publishes/Controllers/ScaffoldInterface/PermissionController.php: -------------------------------------------------------------------------------- 1 | $request->name]); 43 | 44 | return redirect('scaffold-permissions'); 45 | } 46 | 47 | /** 48 | * Show the form for editing the specified resource. 49 | * 50 | * @param int $id 51 | * 52 | * @return \Illuminate\Http\Response 53 | */ 54 | public function edit($id) 55 | { 56 | $permission = Permission::findOrFail($id); 57 | 58 | return view('scaffold-interface.permissions.edit', compact('permission')); 59 | } 60 | 61 | /** 62 | * Update the specified resource in storage. 63 | * 64 | * @param \Illuminate\Http\Request $request 65 | * 66 | * @return \Illuminate\Http\Response 67 | */ 68 | public function update(Request $request) 69 | { 70 | $permission = Permission::findOrFail($request->permission_id); 71 | 72 | $permission->name = $request->name; 73 | 74 | $permission->update(); 75 | 76 | return redirect('scaffold-permissions'); 77 | } 78 | 79 | /** 80 | * Remove the specified resource from storage. 81 | * 82 | * @param int $id 83 | * 84 | * @return \Illuminate\Http\Response 85 | */ 86 | public function destroy($id) 87 | { 88 | $permission = Permission::findOrFail($id); 89 | 90 | $permission->delete(); 91 | 92 | return redirect('scaffold-permissions'); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Publishes/Controllers/ScaffoldInterface/RoleController.php: -------------------------------------------------------------------------------- 1 | $request->name]); 43 | 44 | return redirect('scaffold-roles'); 45 | } 46 | 47 | /** 48 | * Show the form for editing the specified resource. 49 | * 50 | * @param int $id 51 | * 52 | * @return \Illuminate\Http\Response 53 | */ 54 | public function edit($id) 55 | { 56 | $role = Role::findOrFail($id); 57 | 58 | return view('scaffold-interface.roles.edit', compact('role')); 59 | } 60 | 61 | /** 62 | * Update the specified resource in storage. 63 | * 64 | * @param \Illuminate\Http\Request $request 65 | * 66 | * @return \Illuminate\Http\Response 67 | */ 68 | public function update(Request $request) 69 | { 70 | $role = Role::findOrFail($request->role_id); 71 | 72 | $role->name = $request->name; 73 | 74 | $role->update(); 75 | 76 | return redirect('scaffold-roles'); 77 | } 78 | 79 | /** 80 | * Remove the specified resource from storage. 81 | * 82 | * @param int $id 83 | * 84 | * @return \Illuminate\Http\Response 85 | */ 86 | public function destroy($id) 87 | { 88 | $role = Role::findOrFail($id); 89 | 90 | $role->delete(); 91 | 92 | return redirect('scaffold-roles'); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Publishes/Controllers/ScaffoldInterface/UserController.php: -------------------------------------------------------------------------------- 1 | email = $request->email; 47 | $user->name = $request->name; 48 | $user->password = Hash::make($request->password); 49 | 50 | $user->save(); 51 | 52 | return redirect('scaffold-users'); 53 | } 54 | 55 | /** 56 | * Show the form for editing the specified resource. 57 | * 58 | * @param int $id 59 | * 60 | * @return \Illuminate\Http\Response 61 | */ 62 | public function edit($id) 63 | { 64 | $user = \App\User::findOrfail($id); 65 | $roles = Role::all()->pluck('name'); 66 | $permissions = Permission::all()->pluck('name'); 67 | $userRoles = $user->roles; 68 | $userPermissions = $user->permissions; 69 | 70 | return view('scaffold-interface.users.edit', compact('user', 'roles', 'permissions', 'userRoles', 'userPermissions')); 71 | } 72 | 73 | /** 74 | * Update the specified resource in storage. 75 | * 76 | * @param \Illuminate\Http\Request $request 77 | * 78 | * @return \Illuminate\Http\Response 79 | */ 80 | public function update(Request $request) 81 | { 82 | $user = \App\User::findOrfail($request->user_id); 83 | 84 | $user->email = $request->email; 85 | $user->name = $request->name; 86 | $user->password = Hash::make($request->password); 87 | 88 | $user->save(); 89 | 90 | return redirect('scaffold-users'); 91 | } 92 | 93 | /** 94 | * Remove the specified resource from storage. 95 | * 96 | * @param int $id 97 | * 98 | * @return \Illuminate\Http\Response 99 | */ 100 | public function destroy($id) 101 | { 102 | $user = \App\User::findOrfail($id); 103 | 104 | $user->delete(); 105 | 106 | return redirect('scaffold-users'); 107 | } 108 | 109 | /** 110 | * Assign Role to user. 111 | * 112 | * @param \Illuminate\Http\Request 113 | * 114 | * @return \Illuminate\Http\Response 115 | */ 116 | public function addRole(Request $request) 117 | { 118 | $user = \App\User::findOrfail($request->user_id); 119 | $user->assignRole($request->role_name); 120 | 121 | return redirect('scaffold-users/edit/'.$request->user_id); 122 | } 123 | 124 | /** 125 | * Assign Permission to a user. 126 | * 127 | * @param \Illuminate\Http\Request 128 | * 129 | * @return \Illuminate\Http\Response 130 | */ 131 | public function addPermission(Request $request) 132 | { 133 | $user = \App\User::findorfail($request->user_id); 134 | $user->givePermissionTo($request->permission_name); 135 | 136 | return redirect('scaffold-users/edit/'.$request->user_id); 137 | } 138 | 139 | /** 140 | * revoke Permission to a user. 141 | * 142 | * @param \Illuminate\Http\Request 143 | * 144 | * @return \Illuminate\Http\Response 145 | */ 146 | public function revokePermission($permission, $user_id) 147 | { 148 | $user = \App\User::findorfail($user_id); 149 | 150 | $user->revokePermissionTo(str_slug($permission, ' ')); 151 | 152 | return redirect('scaffold-users/edit/'.$user_id); 153 | } 154 | 155 | /** 156 | * revoke Role to a a user. 157 | * 158 | * @param \Illuminate\Http\Request 159 | * 160 | * @return \Illuminate\Http\Response 161 | */ 162 | public function revokeRole($role, $user_id) 163 | { 164 | $user = \App\User::findorfail($user_id); 165 | 166 | $user->removeRole(str_slug($role, ' ')); 167 | 168 | return redirect('scaffold-users/edit/'.$user_id); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/dashboard/dashboard.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('title','Dashboard') 3 | @section('content') 4 |
5 |

6 | Dashboard 7 | Control panel 8 |

9 | 13 |
14 |
15 |
16 |
17 | 18 |
19 |
20 |

{{$users}}

21 |

Users

22 |
23 |
24 | 25 |
26 | More info 27 |
28 |
29 |
30 | 31 |
32 |
33 |

{{$roles}}

34 |

Roles

35 |
36 |
37 | 38 |
39 | More info 40 |
41 |
42 |
43 | 44 |
45 |
46 |

{{$permissions}}

47 |

Permissions

48 |
49 |
50 | 51 |
52 | More info 53 |
54 |
55 | 56 | @foreach($entities as $entity) 57 |
58 | 59 |
60 |
61 |

{{$entity->tablename}}

62 |

{{$entity->tablename}}

63 |
64 |
65 | 66 |
67 | More info 68 |
69 |
70 | @endforeach 71 |
72 |
73 | @endsection 74 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @yield('title') 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 26 | 27 | 28 |
29 |
30 | 31 | 37 | 38 | 91 |
92 | 124 |
125 | @yield('content') 126 |
127 |
128 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/layouts/defaultMaterialize.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @yield('title') 10 | 11 | 12 | @yield('content') 13 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/permissions/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

Create new Permission

7 |
8 |
9 |
10 | {!! csrf_field() !!} 11 |
12 | 13 | 14 |
15 | 18 |
19 |
20 |
21 |
22 | @endsection 23 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/permissions/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

Edit Permission

7 |
8 |
9 |
10 | {!! csrf_field() !!} 11 | 12 |
13 | 14 | 15 |
16 | 19 |
20 |
21 |
22 |
23 | @endsection 24 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/permissions/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

All Permissions

7 |
8 |
9 | New 10 | 11 | 12 | 13 | 14 | 15 | 16 | @foreach($permissions as $permission) 17 | 18 | 19 | 23 | 24 | @endforeach 25 | 26 |
PermissionActions
{{$permission->name}} 20 | 21 | 22 |
27 |
28 |
29 |
30 | @endsection 31 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/roles/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

Create new Role

7 |
8 |
9 |
10 | {!! csrf_field() !!} 11 |
12 | 13 | 14 |
15 | 18 |
19 |
20 |
21 |
22 | @endsection 23 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/roles/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

Edit Role

7 |
8 |
9 |
10 | {!! csrf_field() !!} 11 | 12 |
13 | 14 | 15 |
16 | 19 |
20 |
21 |
22 |
23 | @endsection 24 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/roles/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

All Roles

7 |
8 |
9 | New 10 | 11 | 12 | 13 | 14 | 15 | 16 | @foreach($roles as $role) 17 | 18 | 19 | 23 | 24 | @endforeach 25 | 26 |
RoleActions
{{$role->name}} 20 | 21 | 22 |
27 |
28 |
29 |
30 | @endsection 31 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/users/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

Create new user

7 |
8 |
9 |
10 | {!! csrf_field() !!} 11 | 12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 |
21 | 22 | 23 |
24 | 25 |
26 |
27 |
28 |
29 | @endsection 30 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/users/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

Edit User ({{$user->name}})

7 |
8 |
9 |
10 | {!! csrf_field() !!} 11 | 12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 |
21 | 22 | 23 |
24 | 25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |

{{$user->name}} Roles

33 |
34 |
35 |
36 | {!! csrf_field() !!} 37 | 38 |
39 | 44 |
45 |
46 | 47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | @foreach($userRoles as $role) 56 | 57 | 58 | 59 | 60 | @endforeach 61 | 62 |
RoleAction
{{$role->name}}
63 |
64 |
65 |
66 |
67 |
68 |
69 |

{{$user->name}} Permissions

70 |
71 |
72 |
73 | {!! csrf_field() !!} 74 | 75 |
76 | 81 |
82 |
83 | 84 |
85 |
86 | 87 | 88 | 89 | 90 | 91 | 92 | @foreach($userPermissions as $permission) 93 | 94 | 95 | 96 | 97 | @endforeach 98 | 99 |
PermissionAction
{{$permission->name}}
100 |
101 |
102 |
103 |
104 |
105 | @endsection 106 | -------------------------------------------------------------------------------- /src/Publishes/Views/scaffold-interface/users/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('scaffold-interface.layouts.app') 2 | @section('content') 3 |
4 |
5 |
6 |

All Users

7 |
8 |
9 | New 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @foreach($users as $user) 20 | 21 | 22 | 23 | 32 | 41 | 45 | 46 | @endforeach 47 | 48 |
NameEmailRolesPermissionsActions
{{$user->name}}{{$user->email}} 24 | @if(!empty($user->roles)) 25 | @foreach($user->roles as $role) 26 | {{$role->name}} 27 | @endforeach 28 | @else 29 | No Roles 30 | @endif 31 | 33 | @if(!empty($user->permissions)) 34 | @foreach($user->permissions as $permission) 35 | {{$permission->name}} 36 | @endforeach 37 | @else 38 | No Permissions 39 | @endif 40 | 42 | 43 | 44 |
49 |
50 |
51 |
52 | @endsection 53 | -------------------------------------------------------------------------------- /src/Scaffold.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Scaffold 11 | { 12 | /** 13 | * Generator instance. 14 | * 15 | * @var \Amranidev\ScaffoldInterface\Generators\Generator 16 | */ 17 | public $generator; 18 | 19 | /** 20 | * Create new scaffold instance. 21 | * 22 | * @return void 23 | */ 24 | public function __construct() 25 | { 26 | $this->generator = app()->make('Generator'); 27 | } 28 | 29 | /** 30 | * Scaffold Migration. 31 | * 32 | * @return \Amranidev\ScaffoldInterface\Scaffold 33 | */ 34 | public function migration() 35 | { 36 | $this->generator->migration(); 37 | 38 | return $this; 39 | } 40 | 41 | /** 42 | * Scaffold Model. 43 | * 44 | * @return \Amranidev\ScaffoldInterface\Scaffold 45 | */ 46 | public function model() 47 | { 48 | $this->generator->model(); 49 | 50 | return $this; 51 | } 52 | 53 | /** 54 | * Scaffold Views. 55 | * 56 | * @return \Amranidev\ScaffoldInterface\Scaffold 57 | */ 58 | public function views() 59 | { 60 | $this->generator->dir(); 61 | $this->generator->views(); 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * Scaffold Controller. 68 | * 69 | * @return \Amranidev\ScaffoldInterface\Scaffold 70 | */ 71 | public function controller() 72 | { 73 | $this->generator->controller(); 74 | 75 | return $this; 76 | } 77 | 78 | /** 79 | * Scaffold Route. 80 | * 81 | * @return \Amranidev\ScaffoldInterface\Scaffold 82 | */ 83 | public function route() 84 | { 85 | $this->generator->route(); 86 | 87 | return $this; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/ScaffoldInterfaceServiceProvider.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class ScaffoldInterfaceServiceProvider extends ServiceProvider 15 | { 16 | /** 17 | * Indicates if loading of the provider is deferred. 18 | * 19 | * @var bool 20 | */ 21 | protected $defer = false; 22 | 23 | /** 24 | * Bootstrap the application events. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | // Get namespace. 31 | $nameSpace = $this->app->getNamespace(); 32 | 33 | // Set namespace alias for AppController. 34 | AliasLoader::getInstance()->alias('AppController', $nameSpace.'Http\Controllers\Controller'); 35 | 36 | // Routes. 37 | $this->app->router->group(['namespace' => $nameSpace.'Http\Controllers'], function () { 38 | require __DIR__.'/Http/routes.php'; 39 | }); 40 | 41 | // Public 42 | $this->publishes([__DIR__.'/../resources/assets' => public_path(), 43 | ], 'public'); 44 | 45 | // Views 46 | $this->publishes([__DIR__.'/Publishes/Views' => base_path('/resources/views')], 'views'); 47 | 48 | $this->publishes([__DIR__.'/Publishes/Controllers' => app_path('/Http/Controllers')], 'Controllers'); 49 | 50 | // Load views. 51 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'scaffold-interface'); 52 | 53 | // Migrations. 54 | $this->publishes([ 55 | __DIR__.'/../database/migrations/' => database_path('migrations'), 56 | ], 'migrations'); 57 | 58 | //config path. 59 | $configPath = __DIR__.'/../config/config.php'; 60 | 61 | //Register config. 62 | $this->publishes([ 63 | $configPath => config_path('amranidev/config.php'), ]); 64 | } 65 | 66 | /** 67 | * Register the service provider. 68 | * 69 | * @return void 70 | */ 71 | public function register() 72 | { 73 | $this->app->register(ScaffoldInterfaceEventServiceProvider::class); 74 | 75 | $this->app->singleton('laravelRequest', \Illuminate\Http\Request::class); 76 | 77 | $this->app->singleton('Request', \Amranidev\ScaffoldInterface\Http\Request::class); 78 | 79 | $this->app->singleton('Scaffold', \Amranidev\ScaffoldInterface\Scaffold::class); 80 | 81 | $this->app->singleton('Datasystem', function ($app) { 82 | return new \Amranidev\ScaffoldInterface\Datasystem\Datasystem($app->make('Request')->getRequest()); 83 | }); 84 | 85 | $this->app->singleton('Parser', function ($app) { 86 | return new \Amranidev\ScaffoldInterface\Parsers\Parser($app->make('Request')->getRequest()); 87 | }); 88 | 89 | $this->app->singleton('Indenter', \Gajus\Dindent\Indenter::class); 90 | 91 | $this->app->singleton('Path', \Amranidev\ScaffoldInterface\Filesystem\Path::class); 92 | 93 | $this->app->singleton('Generator', \Amranidev\ScaffoldInterface\Generators\Generator::class); 94 | 95 | $this->app->singleton('ModelGenerate', \Amranidev\ScaffoldInterface\Generators\ModelGenerate::class); 96 | 97 | $this->app->singleton('ViewGenerate', \Amranidev\ScaffoldInterface\Generators\ViewGenerate::class); 98 | 99 | $this->app->singleton('MigrationGenerate', \Amranidev\ScaffoldInterface\Generators\MigrationGenerate::class); 100 | 101 | $this->app->singleton('ControllerGenerate', \Amranidev\ScaffoldInterface\Generators\ControllerGenerate::class); 102 | 103 | $this->app->singleton('RouteGenerate', \Amranidev\ScaffoldInterface\Generators\RouteGenerate::class); 104 | } 105 | } 106 | --------------------------------------------------------------------------------