@@ -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; |