@@ -15,56 +15,56 @@ |
||
| 15 | 15 | |
| 16 | 16 | class {{class_name}}Controller extends Controller |
| 17 | 17 | { |
| 18 | - // blade views |
|
| 19 | - // index view |
|
| 18 | + // blade views |
|
| 19 | + // index view |
|
| 20 | 20 | |
| 21 | - public function show($id) |
|
| 22 | - { |
|
| 23 | - $file = {{class_name}}Model::find($id); |
|
| 24 | - return $file ; |
|
| 25 | - } |
|
| 21 | + public function show($id) |
|
| 22 | + { |
|
| 23 | + $file = {{class_name}}Model::find($id); |
|
| 24 | + return $file ; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function upload() |
|
| 28 | - { |
|
| 29 | - $config = new FlowConfig(); |
|
| 30 | - $config->setTempDir(storage_path() . '/tmp'); |
|
| 31 | - $config->setDeleteChunksOnSave(true); |
|
| 27 | + public function upload() |
|
| 28 | + { |
|
| 29 | + $config = new FlowConfig(); |
|
| 30 | + $config->setTempDir(storage_path() . '/tmp'); |
|
| 31 | + $config->setDeleteChunksOnSave(true); |
|
| 32 | 32 | |
| 33 | - $request = new FlowRequest(); |
|
| 33 | + $request = new FlowRequest(); |
|
| 34 | 34 | |
| 35 | - $totalSize = $request->getTotalSize(); |
|
| 35 | + $totalSize = $request->getTotalSize(); |
|
| 36 | 36 | |
| 37 | - if ($totalSize && $totalSize > (1024 * 1024 * 4)) |
|
| 38 | - { |
|
| 39 | - return $this->responseWithError('File size exceeds 4MB'); |
|
| 40 | - } |
|
| 37 | + if ($totalSize && $totalSize > (1024 * 1024 * 4)) |
|
| 38 | + { |
|
| 39 | + return $this->responseWithError('File size exceeds 4MB'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $requestFile = $request->getFile(); |
|
| 42 | + $requestFile = $request->getFile(); |
|
| 43 | 43 | |
| 44 | - $file = new ScaffolderFile($config, $request); |
|
| 44 | + $file = new ScaffolderFile($config, $request); |
|
| 45 | 45 | |
| 46 | - if ($file->validateChunk()) { |
|
| 47 | - $file->saveChunk(); |
|
| 48 | - } |
|
| 46 | + if ($file->validateChunk()) { |
|
| 47 | + $file->saveChunk(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - if ($file->save(storage_path() . '/tmp/' . $request->getFileName())) |
|
| 51 | - { |
|
| 52 | - $file = FileModel::create([ |
|
| 53 | - 'mime_type' => $requestFile['type'], |
|
| 54 | - 'size' => $requestFile['size'], |
|
| 55 | - 'file_path' => storage_path() . '/tmp/', |
|
| 56 | - 'filename' => $requestFile['name'], |
|
| 57 | - 'disk' => 'local', |
|
| 58 | - 'status' => false, |
|
| 59 | - ]); |
|
| 50 | + if ($file->save(storage_path() . '/tmp/' . $request->getFileName())) |
|
| 51 | + { |
|
| 52 | + $file = FileModel::create([ |
|
| 53 | + 'mime_type' => $requestFile['type'], |
|
| 54 | + 'size' => $requestFile['size'], |
|
| 55 | + 'file_path' => storage_path() . '/tmp/', |
|
| 56 | + 'filename' => $requestFile['name'], |
|
| 57 | + 'disk' => 'local', |
|
| 58 | + 'status' => false, |
|
| 59 | + ]); |
|
| 60 | 60 | |
| 61 | - return $file->id; |
|
| 62 | - } |
|
| 63 | - else |
|
| 64 | - { |
|
| 65 | - // Indicate that we are not done with all the chunks. |
|
| 66 | - return null; |
|
| 67 | - } |
|
| 68 | - } |
|
| 61 | + return $file->id; |
|
| 62 | + } |
|
| 63 | + else |
|
| 64 | + { |
|
| 65 | + // Indicate that we are not done with all the chunks. |
|
| 66 | + return null; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use Illuminate\Http\Request; |
| 6 | 6 | use Illuminate\Pagination\Paginator; |
| 7 | 7 | use App\Http\Controllers\Controller; |
| 8 | -use App\Models\{{class_name}} as {{class_name}}Model;; |
|
| 8 | +use App\Models\{{class_name}} as {{class_name}}Model; ; |
|
| 9 | 9 | use App\Http\Controllers\File as ScaffolderFile; |
| 10 | 10 | use Log; |
| 11 | 11 | use Flow\Config as FlowConfig; |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | public function show($id) |
| 22 | 22 | { |
| 23 | 23 | $file = {{class_name}}Model::find($id); |
| 24 | - return $file ; |
|
| 24 | + return $file; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function upload() |
| 28 | 28 | { |
| 29 | 29 | $config = new FlowConfig(); |
| 30 | - $config->setTempDir(storage_path() . '/tmp'); |
|
| 30 | + $config->setTempDir(storage_path().'/tmp'); |
|
| 31 | 31 | $config->setDeleteChunksOnSave(true); |
| 32 | 32 | |
| 33 | 33 | $request = new FlowRequest(); |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | $file->saveChunk(); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if ($file->save(storage_path() . '/tmp/' . $request->getFileName())) |
|
| 50 | + if ($file->save(storage_path().'/tmp/'.$request->getFileName())) |
|
| 51 | 51 | { |
| 52 | 52 | $file = FileModel::create([ |
| 53 | 53 | 'mime_type' => $requestFile['type'], |
| 54 | 54 | 'size' => $requestFile['size'], |
| 55 | - 'file_path' => storage_path() . '/tmp/', |
|
| 55 | + 'file_path' => storage_path().'/tmp/', |
|
| 56 | 56 | 'filename' => $requestFile['name'], |
| 57 | 57 | 'disk' => 'local', |
| 58 | 58 | 'status' => false, |
@@ -59,8 +59,7 @@ |
||
| 59 | 59 | ]); |
| 60 | 60 | |
| 61 | 61 | return $file->id; |
| 62 | - } |
|
| 63 | - else |
|
| 62 | + } else |
|
| 64 | 63 | { |
| 65 | 64 | // Indicate that we are not done with all the chunks. |
| 66 | 65 | return null; |
@@ -174,8 +174,9 @@ |
||
| 174 | 174 | $success = $model->destroy($ids); |
| 175 | 175 | |
| 176 | 176 | $status = array("error" => true, "message" => "Error deleting object"); |
| 177 | - if ($success) |
|
| 178 | - $status = array("error" => false, "message" => "Object successfully deleted"); |
|
| 177 | + if ($success) { |
|
| 178 | + $status = array("error" => false, "message" => "Object successfully deleted"); |
|
| 179 | + } |
|
| 179 | 180 | |
| 180 | 181 | return json_encode($status); |
| 181 | 182 | |
@@ -14,130 +14,130 @@ |
||
| 14 | 14 | |
| 15 | 15 | class {{class_name}}Controller extends Controller |
| 16 | 16 | { |
| 17 | - // blade views |
|
| 18 | - // index view |
|
| 19 | - public function index() |
|
| 20 | - { |
|
| 21 | - return view('{{class_name_lw}}.index'); |
|
| 22 | - } |
|
| 23 | - // create view |
|
| 24 | - public function create() |
|
| 25 | - { |
|
| 26 | - return view('{{class_name_lw}}.create'); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - // edit view |
|
| 30 | - public function edit($id) |
|
| 31 | - { |
|
| 32 | - ${{class_name_lw}} = {{class_name}}::find($id); |
|
| 33 | - |
|
| 34 | - return view('{{class_name_lw}}.edit')->with('model', ${{class_name_lw}}); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // api resources |
|
| 17 | + // blade views |
|
| 18 | + // index view |
|
| 19 | + public function index() |
|
| 20 | + { |
|
| 21 | + return view('{{class_name_lw}}.index'); |
|
| 22 | + } |
|
| 23 | + // create view |
|
| 24 | + public function create() |
|
| 25 | + { |
|
| 26 | + return view('{{class_name_lw}}.create'); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + // edit view |
|
| 30 | + public function edit($id) |
|
| 31 | + { |
|
| 32 | + ${{class_name_lw}} = {{class_name}}::find($id); |
|
| 33 | + |
|
| 34 | + return view('{{class_name_lw}}.edit')->with('model', ${{class_name_lw}}); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // api resources |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - // save {{class_name_lw}} |
|
| 41 | - public function store(Request $request) |
|
| 42 | - { |
|
| 43 | - // validate {{class_name_lw}} and eager objects |
|
| 44 | - $this->validate($request, $this->getRules()); |
|
| 40 | + // save {{class_name_lw}} |
|
| 41 | + public function store(Request $request) |
|
| 42 | + { |
|
| 43 | + // validate {{class_name_lw}} and eager objects |
|
| 44 | + $this->validate($request, $this->getRules()); |
|
| 45 | 45 | |
| 46 | - $model = new {{class_name}}(); |
|
| 46 | + $model = new {{class_name}}(); |
|
| 47 | 47 | |
| 48 | - ${{class_name_lw}} = $model->store($request); |
|
| 48 | + ${{class_name_lw}} = $model->store($request); |
|
| 49 | 49 | |
| 50 | - return ${{class_name_lw}}; |
|
| 51 | - } |
|
| 50 | + return ${{class_name_lw}}; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // update {{class_name_lw}} by id |
|
| 54 | - public function update($id, Request $request) |
|
| 55 | - { |
|
| 56 | - // validate {{table_name}} and eager objects |
|
| 57 | - $this->validate($request, $this->getRules($id)); |
|
| 53 | + // update {{class_name_lw}} by id |
|
| 54 | + public function update($id, Request $request) |
|
| 55 | + { |
|
| 56 | + // validate {{table_name}} and eager objects |
|
| 57 | + $this->validate($request, $this->getRules($id)); |
|
| 58 | 58 | |
| 59 | - $model = new {{class_name}}(); |
|
| 60 | - ${{class_name_lw}} = $model->updateModel($id, $request); |
|
| 61 | - |
|
| 62 | - return ${{class_name_lw}}; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - // get {{class_name_lw}} by id |
|
| 67 | - public function show($id) |
|
| 68 | - { |
|
| 69 | - $model = new {{class_name}}(); |
|
| 70 | - ${{class_name_lw}} = $model->show($id); |
|
| 71 | - return ${{class_name_lw}} ; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // find first by field and value |
|
| 75 | - public function findByField(Request $request) |
|
| 76 | - { |
|
| 77 | - $model = new {{class_name}}(); |
|
| 78 | - ${{class_name_lw}} = $model->findByField($request); |
|
| 79 | - return ${{class_name_lw}} ; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // build all validation rules |
|
| 83 | - protected function getRules($id = null){ |
|
| 84 | - // default object rules |
|
| 85 | - $model = new {{class_name}}(); |
|
| 86 | - $rules = $model::$rules; |
|
| 87 | - ${{class_name_lw}} = $model->show($id); |
|
| 88 | - {{unique_rules}} |
|
| 89 | - // nested rules for eager objects |
|
| 90 | - {{rules_eager}} |
|
| 59 | + $model = new {{class_name}}(); |
|
| 60 | + ${{class_name_lw}} = $model->updateModel($id, $request); |
|
| 61 | + |
|
| 62 | + return ${{class_name_lw}}; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + // get {{class_name_lw}} by id |
|
| 67 | + public function show($id) |
|
| 68 | + { |
|
| 69 | + $model = new {{class_name}}(); |
|
| 70 | + ${{class_name_lw}} = $model->show($id); |
|
| 71 | + return ${{class_name_lw}} ; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // find first by field and value |
|
| 75 | + public function findByField(Request $request) |
|
| 76 | + { |
|
| 77 | + $model = new {{class_name}}(); |
|
| 78 | + ${{class_name_lw}} = $model->findByField($request); |
|
| 79 | + return ${{class_name_lw}} ; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // build all validation rules |
|
| 83 | + protected function getRules($id = null){ |
|
| 84 | + // default object rules |
|
| 85 | + $model = new {{class_name}}(); |
|
| 86 | + $rules = $model::$rules; |
|
| 87 | + ${{class_name_lw}} = $model->show($id); |
|
| 88 | + {{unique_rules}} |
|
| 89 | + // nested rules for eager objects |
|
| 90 | + {{rules_eager}} |
|
| 91 | 91 | |
| 92 | - return $rules; |
|
| 93 | - } |
|
| 92 | + return $rules; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - // delete model by ids |
|
| 96 | - public function destroy($id) |
|
| 97 | - { |
|
| 98 | - $ids = explode(",", $id); |
|
| 99 | - $ids = array_unique($ids); |
|
| 95 | + // delete model by ids |
|
| 96 | + public function destroy($id) |
|
| 97 | + { |
|
| 98 | + $ids = explode(",", $id); |
|
| 99 | + $ids = array_unique($ids); |
|
| 100 | 100 | |
| 101 | - $model = new {{class_name}}(); |
|
| 101 | + $model = new {{class_name}}(); |
|
| 102 | 102 | |
| 103 | - $success = $model->destroy($ids); |
|
| 103 | + $success = $model->destroy($ids); |
|
| 104 | 104 | |
| 105 | - $status = array("error" => true, "message" => "Error deleting object"); |
|
| 106 | - if ($success) |
|
| 107 | - $status = array("error" => false, "message" => "Object successfully deleted"); |
|
| 105 | + $status = array("error" => true, "message" => "Error deleting object"); |
|
| 106 | + if ($success) |
|
| 107 | + $status = array("error" => false, "message" => "Object successfully deleted"); |
|
| 108 | 108 | |
| 109 | - return json_encode($status); |
|
| 109 | + return json_encode($status); |
|
| 110 | 110 | |
| 111 | - } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - {{reverseRelationships}} |
|
| 114 | - {{relationship_tables_store}} |
|
| 115 | - {{remove_relationship_objects}} |
|
| 116 | - {{enum}} |
|
| 117 | - {{checkbox}} |
|
| 113 | + {{reverseRelationships}} |
|
| 114 | + {{relationship_tables_store}} |
|
| 115 | + {{remove_relationship_objects}} |
|
| 116 | + {{enum}} |
|
| 117 | + {{checkbox}} |
|
| 118 | 118 | |
| 119 | 119 | |
| 120 | - // query with search and pagination options |
|
| 121 | - public function query(Request $request) |
|
| 122 | - { |
|
| 123 | - $model = new {{class_name}}(); |
|
| 120 | + // query with search and pagination options |
|
| 121 | + public function query(Request $request) |
|
| 122 | + { |
|
| 123 | + $model = new {{class_name}}(); |
|
| 124 | 124 | |
| 125 | - $query = $model->querySearch($request); |
|
| 125 | + $query = $model->querySearch($request); |
|
| 126 | 126 | |
| 127 | - return $query; |
|
| 128 | - } |
|
| 127 | + return $query; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | |
| 131 | - // query with fields filters and pagination |
|
| 132 | - //json = {"pagination": {"actual": 1, "itensPerPage": 20}, "fields": ["name","email","cnpj"], "orderBy": "name"} |
|
| 133 | - public function queryFilters(Request $request) |
|
| 134 | - { |
|
| 135 | - $model = new {{class_name}}(); |
|
| 131 | + // query with fields filters and pagination |
|
| 132 | + //json = {"pagination": {"actual": 1, "itensPerPage": 20}, "fields": ["name","email","cnpj"], "orderBy": "name"} |
|
| 133 | + public function queryFilters(Request $request) |
|
| 134 | + { |
|
| 135 | + $model = new {{class_name}}(); |
|
| 136 | 136 | |
| 137 | - ${{class_name_lw}} = $model->queryFilters($request); |
|
| 137 | + ${{class_name_lw}} = $model->queryFilters($request); |
|
| 138 | 138 | |
| 139 | - return ${{class_name_lw}}; |
|
| 140 | - } |
|
| 139 | + return ${{class_name_lw}}; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | } |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // build all validation rules |
| 83 | - protected function getRules($id = null){ |
|
| 83 | + protected function getRules($id = null) { |
|
| 84 | 84 | // default object rules |
| 85 | 85 | $model = new {{class_name}}(); |
| 86 | 86 | $rules = $model::$rules; |
@@ -13,209 +13,209 @@ |
||
| 13 | 13 | |
| 14 | 14 | class {{class_name}} extends Model |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * The database table used by the model. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - protected $table = '{{table_name}}'; |
|
| 22 | - {{timestamps}} |
|
| 23 | - |
|
| 24 | - {{primaryAttribute}} |
|
| 25 | - public $fillable = [ |
|
| 26 | - {{fillable}} |
|
| 27 | - ]; |
|
| 28 | - |
|
| 29 | - // validation rules |
|
| 30 | - public static $rules = [ |
|
| 31 | - {{validations}} |
|
| 32 | - ]; |
|
| 33 | - |
|
| 34 | - // eager loading objects |
|
| 35 | - public $with = [ |
|
| 36 | - {{eager}} |
|
| 37 | - ]; |
|
| 38 | - |
|
| 39 | - {{enum}} |
|
| 40 | - |
|
| 41 | - {{belongsTo}} |
|
| 42 | - |
|
| 43 | - {{reverseRelationship}} |
|
| 16 | + /** |
|
| 17 | + * The database table used by the model. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + protected $table = '{{table_name}}'; |
|
| 22 | + {{timestamps}} |
|
| 23 | + |
|
| 24 | + {{primaryAttribute}} |
|
| 25 | + public $fillable = [ |
|
| 26 | + {{fillable}} |
|
| 27 | + ]; |
|
| 28 | + |
|
| 29 | + // validation rules |
|
| 30 | + public static $rules = [ |
|
| 31 | + {{validations}} |
|
| 32 | + ]; |
|
| 33 | + |
|
| 34 | + // eager loading objects |
|
| 35 | + public $with = [ |
|
| 36 | + {{eager}} |
|
| 37 | + ]; |
|
| 38 | + |
|
| 39 | + {{enum}} |
|
| 40 | + |
|
| 41 | + {{belongsTo}} |
|
| 42 | + |
|
| 43 | + {{reverseRelationship}} |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - //api resources |
|
| 46 | + //api resources |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - // save {{class_name_lw}} |
|
| 51 | - public function store(Request $request) |
|
| 52 | - { |
|
| 53 | - $vars = $request->all(); |
|
| 50 | + // save {{class_name_lw}} |
|
| 51 | + public function store(Request $request) |
|
| 52 | + { |
|
| 53 | + $vars = $request->all(); |
|
| 54 | 54 | |
| 55 | - //create eager objects |
|
| 56 | - {{store_eager_objects}} |
|
| 55 | + //create eager objects |
|
| 56 | + {{store_eager_objects}} |
|
| 57 | 57 | |
| 58 | - ${{class_name_lw}} = {{class_name}}::create($vars); |
|
| 58 | + ${{class_name_lw}} = {{class_name}}::create($vars); |
|
| 59 | 59 | |
| 60 | - //create relationship_tables objects |
|
| 61 | - {{relationship_tables_call}} |
|
| 60 | + //create relationship_tables objects |
|
| 61 | + {{relationship_tables_call}} |
|
| 62 | 62 | |
| 63 | - return ${{class_name_lw}} ; |
|
| 64 | - } |
|
| 63 | + return ${{class_name_lw}} ; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - // get {{class_name_lw}} by id |
|
| 68 | - public function show($id) |
|
| 69 | - { |
|
| 70 | - ${{class_name_lw}} = {{class_name}}::find($id); |
|
| 71 | - return ${{class_name_lw}}; |
|
| 72 | - } |
|
| 67 | + // get {{class_name_lw}} by id |
|
| 68 | + public function show($id) |
|
| 69 | + { |
|
| 70 | + ${{class_name_lw}} = {{class_name}}::find($id); |
|
| 71 | + return ${{class_name_lw}}; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | |
| 76 | - //get first row by field and value |
|
| 77 | - public function findByField(Request $request) |
|
| 78 | - { |
|
| 79 | - ${{class_name_lw}} = {{class_name}}::where($request->input('field') , '=', $request->input('value'))->first(); |
|
| 80 | - return ${{class_name_lw}} ; |
|
| 81 | - } |
|
| 76 | + //get first row by field and value |
|
| 77 | + public function findByField(Request $request) |
|
| 78 | + { |
|
| 79 | + ${{class_name_lw}} = {{class_name}}::where($request->input('field') , '=', $request->input('value'))->first(); |
|
| 80 | + return ${{class_name_lw}} ; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - // update {{class_name_lw}} by id |
|
| 85 | - public function updateModel($id, Request $request) |
|
| 86 | - { |
|
| 87 | - // get vars |
|
| 88 | - $vars = $request->all(); |
|
| 84 | + // update {{class_name_lw}} by id |
|
| 85 | + public function updateModel($id, Request $request) |
|
| 86 | + { |
|
| 87 | + // get vars |
|
| 88 | + $vars = $request->all(); |
|
| 89 | 89 | |
| 90 | - //update eager objects |
|
| 91 | - {{update_eager_objects}} |
|
| 90 | + //update eager objects |
|
| 91 | + {{update_eager_objects}} |
|
| 92 | 92 | |
| 93 | - ${{class_name_lw}} = {{class_name}}::find($id); |
|
| 94 | - ${{class_name_lw}}->fill($vars); |
|
| 95 | - ${{class_name_lw}}->save(); |
|
| 93 | + ${{class_name_lw}} = {{class_name}}::find($id); |
|
| 94 | + ${{class_name_lw}}->fill($vars); |
|
| 95 | + ${{class_name_lw}}->save(); |
|
| 96 | 96 | |
| 97 | - //update relationship_tables objects |
|
| 98 | - {{remove_relationship_objects_call}} |
|
| 97 | + //update relationship_tables objects |
|
| 98 | + {{remove_relationship_objects_call}} |
|
| 99 | 99 | |
| 100 | - {{relationship_tables_call}} |
|
| 100 | + {{relationship_tables_call}} |
|
| 101 | 101 | |
| 102 | - return ${{class_name_lw}}; |
|
| 103 | - } |
|
| 102 | + return ${{class_name_lw}}; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | - // delete model by id or ids |
|
| 107 | - public static function destroy($ids) |
|
| 108 | - { |
|
| 109 | - $success = {{class_name}}::whereIn('id', $ids)->delete(); |
|
| 106 | + // delete model by id or ids |
|
| 107 | + public static function destroy($ids) |
|
| 108 | + { |
|
| 109 | + $success = {{class_name}}::whereIn('id', $ids)->delete(); |
|
| 110 | 110 | |
| 111 | - return $success; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // query with search and pagination options |
|
| 115 | - public function querySearch(Request $request) |
|
| 116 | - { |
|
| 117 | - // get query parameters |
|
| 118 | - $params = $request->all(); |
|
| 119 | - |
|
| 120 | - // get pagination conditions |
|
| 121 | - if(isset($params["pagination"])) { |
|
| 122 | - $pagination = $params["pagination"]; |
|
| 123 | - } |
|
| 124 | - else { // set default |
|
| 125 | - $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // resolve current page |
|
| 129 | - $currentPage = $pagination["actual"]; |
|
| 130 | - Paginator::currentPageResolver(function () use ($currentPage) { |
|
| 131 | - return $currentPage; |
|
| 132 | - }); |
|
| 133 | - |
|
| 134 | - // set first condition 1=1 (all results) |
|
| 135 | - $query = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
|
| 136 | - |
|
| 137 | - // get filters conditions |
|
| 138 | - $filters = isset($params["filters"]) ? $params["filters"] : $params; |
|
| 111 | + return $success; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // query with search and pagination options |
|
| 115 | + public function querySearch(Request $request) |
|
| 116 | + { |
|
| 117 | + // get query parameters |
|
| 118 | + $params = $request->all(); |
|
| 119 | + |
|
| 120 | + // get pagination conditions |
|
| 121 | + if(isset($params["pagination"])) { |
|
| 122 | + $pagination = $params["pagination"]; |
|
| 123 | + } |
|
| 124 | + else { // set default |
|
| 125 | + $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // resolve current page |
|
| 129 | + $currentPage = $pagination["actual"]; |
|
| 130 | + Paginator::currentPageResolver(function () use ($currentPage) { |
|
| 131 | + return $currentPage; |
|
| 132 | + }); |
|
| 133 | + |
|
| 134 | + // set first condition 1=1 (all results) |
|
| 135 | + $query = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
|
| 136 | + |
|
| 137 | + // get filters conditions |
|
| 138 | + $filters = isset($params["filters"]) ? $params["filters"] : $params; |
|
| 139 | 139 | |
| 140 | - // field by field condition |
|
| 141 | - {{conditions}} |
|
| 140 | + // field by field condition |
|
| 141 | + {{conditions}} |
|
| 142 | 142 | |
| 143 | - // join eager objects |
|
| 144 | - {{eager_joins}} |
|
| 143 | + // join eager objects |
|
| 144 | + {{eager_joins}} |
|
| 145 | 145 | |
| 146 | - // eager object condition |
|
| 147 | - {{eager_conditions}} |
|
| 146 | + // eager object condition |
|
| 147 | + {{eager_conditions}} |
|
| 148 | 148 | |
| 149 | - // join relationship tables objects |
|
| 150 | - {{relationship_tables_joins}} |
|
| 151 | - // get sort clauses |
|
| 152 | - if(isset($params["sort"]) && count($params["sort"])) { |
|
| 153 | - foreach($params["sort"] as $sort){ |
|
| 154 | - {{relationship_tables_joins_sort}} |
|
| 155 | - $query->orderBy($sort["field"], $sort["order"]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 149 | + // join relationship tables objects |
|
| 150 | + {{relationship_tables_joins}} |
|
| 151 | + // get sort clauses |
|
| 152 | + if(isset($params["sort"]) && count($params["sort"])) { |
|
| 153 | + foreach($params["sort"] as $sort){ |
|
| 154 | + {{relationship_tables_joins_sort}} |
|
| 155 | + $query->orderBy($sort["field"], $sort["order"]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | |
| 161 | - return $query->paginate($pagination["itensPerPage"]); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - // query with fields filters and pagination |
|
| 166 | - //json = {"pagination": {"actual": 1, "itensPerPage": 20}, "fields": ["name","email","cnpj"], "orderBy": "name"} |
|
| 167 | - public function queryFilters(Request $request) |
|
| 168 | - { |
|
| 169 | - // get query parameters |
|
| 170 | - $params = $request->all(); |
|
| 171 | - |
|
| 172 | - $orderBy = '{{primary_key}}'; |
|
| 173 | - $fields = null; |
|
| 174 | - $selectArray = []; |
|
| 175 | - array_push($selectArray,'{{primary_key}}'); |
|
| 176 | - |
|
| 177 | - // get pagination conditions |
|
| 178 | - if(isset($params["pagination"])) { |
|
| 179 | - $pagination = $params["pagination"]; |
|
| 180 | - } |
|
| 181 | - else { // set default |
|
| 182 | - $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // resolve current page |
|
| 186 | - $currentPage = $pagination["actual"]; |
|
| 187 | - Paginator::currentPageResolver(function () use ($currentPage) { |
|
| 188 | - return $currentPage; |
|
| 189 | - }); |
|
| 190 | - |
|
| 191 | - if(isset($params["fields"])) { |
|
| 192 | - $fields = $params["fields"]; |
|
| 193 | - |
|
| 194 | - foreach ($fields as $field) { |
|
| 195 | - if(Schema::hasColumn('{{table_name}}', $field)){ |
|
| 196 | - array_push($selectArray, $field); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if(isset($params["orderBy"])) { |
|
| 203 | - if(Schema::hasColumn('{{table_name}}',$params["orderBy"])){ |
|
| 204 | - $orderBy = $params["orderBy"]; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - ${{class_name_lw}} = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
|
| 209 | - |
|
| 210 | - ${{class_name_lw}}->select($selectArray)->orderBy($orderBy,'asc'); |
|
| 161 | + return $query->paginate($pagination["itensPerPage"]); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + // query with fields filters and pagination |
|
| 166 | + //json = {"pagination": {"actual": 1, "itensPerPage": 20}, "fields": ["name","email","cnpj"], "orderBy": "name"} |
|
| 167 | + public function queryFilters(Request $request) |
|
| 168 | + { |
|
| 169 | + // get query parameters |
|
| 170 | + $params = $request->all(); |
|
| 171 | + |
|
| 172 | + $orderBy = '{{primary_key}}'; |
|
| 173 | + $fields = null; |
|
| 174 | + $selectArray = []; |
|
| 175 | + array_push($selectArray,'{{primary_key}}'); |
|
| 176 | + |
|
| 177 | + // get pagination conditions |
|
| 178 | + if(isset($params["pagination"])) { |
|
| 179 | + $pagination = $params["pagination"]; |
|
| 180 | + } |
|
| 181 | + else { // set default |
|
| 182 | + $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // resolve current page |
|
| 186 | + $currentPage = $pagination["actual"]; |
|
| 187 | + Paginator::currentPageResolver(function () use ($currentPage) { |
|
| 188 | + return $currentPage; |
|
| 189 | + }); |
|
| 190 | + |
|
| 191 | + if(isset($params["fields"])) { |
|
| 192 | + $fields = $params["fields"]; |
|
| 193 | + |
|
| 194 | + foreach ($fields as $field) { |
|
| 195 | + if(Schema::hasColumn('{{table_name}}', $field)){ |
|
| 196 | + array_push($selectArray, $field); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if(isset($params["orderBy"])) { |
|
| 203 | + if(Schema::hasColumn('{{table_name}}',$params["orderBy"])){ |
|
| 204 | + $orderBy = $params["orderBy"]; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + ${{class_name_lw}} = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
|
| 209 | + |
|
| 210 | + ${{class_name_lw}}->select($selectArray)->orderBy($orderBy,'asc'); |
|
| 211 | 211 | |
| 212 | - return ${{class_name_lw}}->paginate($pagination["itensPerPage"]); |
|
| 213 | - } |
|
| 212 | + return ${{class_name_lw}}->paginate($pagination["itensPerPage"]); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | |
| 216 | - {{relationship_tables_store}} |
|
| 216 | + {{relationship_tables_store}} |
|
| 217 | 217 | |
| 218 | - {{remove_relationship_objects}} |
|
| 218 | + {{remove_relationship_objects}} |
|
| 219 | 219 | |
| 220 | - {{checkbox}} |
|
| 220 | + {{checkbox}} |
|
| 221 | 221 | } |
| 222 | 222 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | // validation rules |
| 30 | - public static $rules = [ |
|
| 30 | + public static $rules = [ |
|
| 31 | 31 | {{validations}} |
| 32 | 32 | ]; |
| 33 | 33 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | //get first row by field and value |
| 77 | 77 | public function findByField(Request $request) |
| 78 | 78 | { |
| 79 | - ${{class_name_lw}} = {{class_name}}::where($request->input('field') , '=', $request->input('value'))->first(); |
|
| 79 | + ${{class_name_lw}} = {{class_name}}::where($request->input('field'), '=', $request->input('value'))->first(); |
|
| 80 | 80 | return ${{class_name_lw}} ; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -118,16 +118,16 @@ discard block |
||
| 118 | 118 | $params = $request->all(); |
| 119 | 119 | |
| 120 | 120 | // get pagination conditions |
| 121 | - if(isset($params["pagination"])) { |
|
| 121 | + if (isset($params["pagination"])) { |
|
| 122 | 122 | $pagination = $params["pagination"]; |
| 123 | 123 | } |
| 124 | 124 | else { // set default |
| 125 | - $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
|
| 125 | + $pagination = ["actual" => 1, "itensPerPage" => 25]; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // resolve current page |
| 129 | 129 | $currentPage = $pagination["actual"]; |
| 130 | - Paginator::currentPageResolver(function () use ($currentPage) { |
|
| 130 | + Paginator::currentPageResolver(function() use ($currentPage) { |
|
| 131 | 131 | return $currentPage; |
| 132 | 132 | }); |
| 133 | 133 | |
@@ -149,8 +149,8 @@ discard block |
||
| 149 | 149 | // join relationship tables objects |
| 150 | 150 | {{relationship_tables_joins}} |
| 151 | 151 | // get sort clauses |
| 152 | - if(isset($params["sort"]) && count($params["sort"])) { |
|
| 153 | - foreach($params["sort"] as $sort){ |
|
| 152 | + if (isset($params["sort"]) && count($params["sort"])) { |
|
| 153 | + foreach ($params["sort"] as $sort) { |
|
| 154 | 154 | {{relationship_tables_joins_sort}} |
| 155 | 155 | $query->orderBy($sort["field"], $sort["order"]); |
| 156 | 156 | } |
@@ -172,42 +172,42 @@ discard block |
||
| 172 | 172 | $orderBy = '{{primary_key}}'; |
| 173 | 173 | $fields = null; |
| 174 | 174 | $selectArray = []; |
| 175 | - array_push($selectArray,'{{primary_key}}'); |
|
| 175 | + array_push($selectArray, '{{primary_key}}'); |
|
| 176 | 176 | |
| 177 | 177 | // get pagination conditions |
| 178 | - if(isset($params["pagination"])) { |
|
| 178 | + if (isset($params["pagination"])) { |
|
| 179 | 179 | $pagination = $params["pagination"]; |
| 180 | 180 | } |
| 181 | 181 | else { // set default |
| 182 | - $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
|
| 182 | + $pagination = ["actual" => 1, "itensPerPage" => 25]; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // resolve current page |
| 186 | 186 | $currentPage = $pagination["actual"]; |
| 187 | - Paginator::currentPageResolver(function () use ($currentPage) { |
|
| 187 | + Paginator::currentPageResolver(function() use ($currentPage) { |
|
| 188 | 188 | return $currentPage; |
| 189 | 189 | }); |
| 190 | 190 | |
| 191 | - if(isset($params["fields"])) { |
|
| 191 | + if (isset($params["fields"])) { |
|
| 192 | 192 | $fields = $params["fields"]; |
| 193 | 193 | |
| 194 | 194 | foreach ($fields as $field) { |
| 195 | - if(Schema::hasColumn('{{table_name}}', $field)){ |
|
| 195 | + if (Schema::hasColumn('{{table_name}}', $field)) { |
|
| 196 | 196 | array_push($selectArray, $field); |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if(isset($params["orderBy"])) { |
|
| 203 | - if(Schema::hasColumn('{{table_name}}',$params["orderBy"])){ |
|
| 202 | + if (isset($params["orderBy"])) { |
|
| 203 | + if (Schema::hasColumn('{{table_name}}', $params["orderBy"])) { |
|
| 204 | 204 | $orderBy = $params["orderBy"]; |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | ${{class_name_lw}} = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
| 209 | 209 | |
| 210 | - ${{class_name_lw}}->select($selectArray)->orderBy($orderBy,'asc'); |
|
| 210 | + ${{class_name_lw}}->select($selectArray)->orderBy($orderBy, 'asc'); |
|
| 211 | 211 | |
| 212 | 212 | return ${{class_name_lw}}->paginate($pagination["itensPerPage"]); |
| 213 | 213 | } |
@@ -120,8 +120,7 @@ discard block |
||
| 120 | 120 | // get pagination conditions |
| 121 | 121 | if(isset($params["pagination"])) { |
| 122 | 122 | $pagination = $params["pagination"]; |
| 123 | - } |
|
| 124 | - else { // set default |
|
| 123 | + } else { // set default |
|
| 125 | 124 | $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
| 126 | 125 | } |
| 127 | 126 | |
@@ -177,8 +176,7 @@ discard block |
||
| 177 | 176 | // get pagination conditions |
| 178 | 177 | if(isset($params["pagination"])) { |
| 179 | 178 | $pagination = $params["pagination"]; |
| 180 | - } |
|
| 181 | - else { // set default |
|
| 179 | + } else { // set default |
|
| 182 | 180 | $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
| 183 | 181 | } |
| 184 | 182 | |
@@ -7,26 +7,26 @@ |
||
| 7 | 7 | |
| 8 | 8 | class {{class_name}} extends Model |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The database table used by the model. |
|
| 12 | - * |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $table = '{{table_name}}'; |
|
| 10 | + /** |
|
| 11 | + * The database table used by the model. |
|
| 12 | + * |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $table = '{{table_name}}'; |
|
| 16 | 16 | |
| 17 | - {{primaryAttribute}} |
|
| 18 | - public $fillable = [ |
|
| 19 | - {{fillable}} |
|
| 20 | - ]; |
|
| 17 | + {{primaryAttribute}} |
|
| 18 | + public $fillable = [ |
|
| 19 | + {{fillable}} |
|
| 20 | + ]; |
|
| 21 | 21 | |
| 22 | - public static function boot() |
|
| 23 | - { |
|
| 24 | - parent::boot(); |
|
| 22 | + public static function boot() |
|
| 23 | + { |
|
| 24 | + parent::boot(); |
|
| 25 | 25 | |
| 26 | - static::deleting(function($model) |
|
| 27 | - { |
|
| 28 | - Storage::disk($model->disk)->delete($model->file_path); |
|
| 29 | - }); |
|
| 30 | - } |
|
| 26 | + static::deleting(function($model) |
|
| 27 | + { |
|
| 28 | + Storage::disk($model->disk)->delete($model->file_path); |
|
| 29 | + }); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -5,21 +5,21 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Create{{class_name}}Table extends Migration |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Run the migrations. |
|
| 10 | - */ |
|
| 11 | - public function up() |
|
| 12 | - { |
|
| 13 | - Schema::create('{{table_name}}', function (Blueprint $table) { |
|
| 8 | + /** |
|
| 9 | + * Run the migrations. |
|
| 10 | + */ |
|
| 11 | + public function up() |
|
| 12 | + { |
|
| 13 | + Schema::create('{{table_name}}', function (Blueprint $table) { |
|
| 14 | 14 | {{fields}} |
| 15 | - }); |
|
| 16 | - } |
|
| 15 | + }); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Reverse the migrations. |
|
| 20 | - */ |
|
| 21 | - public function down() |
|
| 22 | - { |
|
| 23 | - Schema::drop('{{table_name}}'); |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * Reverse the migrations. |
|
| 20 | + */ |
|
| 21 | + public function down() |
|
| 22 | + { |
|
| 23 | + Schema::drop('{{table_name}}'); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -3,14 +3,14 @@ |
||
| 3 | 3 | use Illuminate\Database\Schema\Blueprint; |
| 4 | 4 | use Illuminate\Database\Migrations\Migration; |
| 5 | 5 | |
| 6 | -class Create{{class_name}}Table extends Migration |
|
| 6 | +class Create {{class_name}}Table extends Migration |
|
| 7 | 7 | { |
| 8 | 8 | /** |
| 9 | 9 | * Run the migrations. |
| 10 | 10 | */ |
| 11 | 11 | public function up() |
| 12 | 12 | { |
| 13 | - Schema::create('{{table_name}}', function (Blueprint $table) { |
|
| 13 | + Schema::create('{{table_name}}', function(Blueprint $table) { |
|
| 14 | 14 | {{fields}} |
| 15 | 15 | }); |
| 16 | 16 | } |