Completed
Push — master ( 28be9d...cc0dae )
by Raphael
02:46
created
src/Scaffolder/Compilers/Core/RouteCompiler.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -10,165 +10,165 @@
 block discarded – undo
10 10
 
11 11
 class RouteCompiler extends AbstractCompiler
12 12
 {
13
-	protected $stubFilename = 'Routes.php' ;
13
+    protected $stubFilename = 'Routes.php' ;
14 14
 
15
-	protected $stubResourceFilename = 'ResourceRoute.php' ;
16
-	protected $stubResource  ;
15
+    protected $stubResourceFilename = 'ResourceRoute.php' ;
16
+    protected $stubResource  ;
17 17
 
18 18
 
19
-	public function __construct($scaffolderConfig, $modelData = null)
20
-	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
-		parent::__construct($scaffolderConfig, null);
19
+    public function __construct($scaffolderConfig, $modelData = null)
20
+    {
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
+        parent::__construct($scaffolderConfig, null);
23 23
 		
24
-		$this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
25
-	}
26
-
27
-	/**
28
-	 * Replace and store the Stub.
29
-	 *
30
-	 * @return string
31
-	 */
32
-	public function replaceAndStore(){}
33
-
34
-	/**
35
-	 * Compiles a resource.
36
-	 *
37
-	 * @param      $hash
38
-	 * @param null $extra
39
-	 *
40
-	 * @return string
41
-	 */
42
-	public function compile($extra = null) {}
43
-
44
-	/**
45
-	 * Compiles a group of routes.
46
-	 *
47
-	 * @param      $hash
48
-	 * @param null $extra
49
-	 *
50
-	 * @return mixed
51
-	 */
52
-	public function compileGroup($compiledRoutes)
53
-	{
54
-
55
-		$this->replaceRoutes($compiledRoutes)
56
-			->replaceRoutePrefix()
57
-			->store(new FileToCompile(null, null));
58
-
59
-		return $this->stub;
60
-	}
61
-
62
-
63
-	/**
64
-	 * Get output filename
65
-	 *
66
-	 *
67
-	 * @return $this
68
-	 */
69
-	protected function getOutputFilename()
70
-	{
71
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes);
72
-
73
-		return $folder  . 'routes.php';
74
-	}
75
-
76
-
77
-	/**
78
-	 * Replace the resource.
79
-	 *
80
-	 * @param $this->modelName
81
-	 *
82
-	 * @return string routeStub
83
-	 */
84
-	public function replaceResource($modelData)
85
-	{
24
+        $this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
25
+    }
26
+
27
+    /**
28
+     * Replace and store the Stub.
29
+     *
30
+     * @return string
31
+     */
32
+    public function replaceAndStore(){}
33
+
34
+    /**
35
+     * Compiles a resource.
36
+     *
37
+     * @param      $hash
38
+     * @param null $extra
39
+     *
40
+     * @return string
41
+     */
42
+    public function compile($extra = null) {}
43
+
44
+    /**
45
+     * Compiles a group of routes.
46
+     *
47
+     * @param      $hash
48
+     * @param null $extra
49
+     *
50
+     * @return mixed
51
+     */
52
+    public function compileGroup($compiledRoutes)
53
+    {
54
+
55
+        $this->replaceRoutes($compiledRoutes)
56
+            ->replaceRoutePrefix()
57
+            ->store(new FileToCompile(null, null));
58
+
59
+        return $this->stub;
60
+    }
61
+
62
+
63
+    /**
64
+     * Get output filename
65
+     *
66
+     *
67
+     * @return $this
68
+     */
69
+    protected function getOutputFilename()
70
+    {
71
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes);
72
+
73
+        return $folder  . 'routes.php';
74
+    }
75
+
76
+
77
+    /**
78
+     * Replace the resource.
79
+     *
80
+     * @param $this->modelName
81
+     *
82
+     * @return string routeStub
83
+     */
84
+    public function replaceResource($modelData)
85
+    {
86 86
 		
87
-		$routeStub = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $this->stubResource);
88
-		$routeStub = str_replace('{{resource}}', $modelData->modelName, $routeStub);
89
-		$routeStub = str_replace('{{reverseRelationships}}', $this->replaceReverseRelationships($modelData), $routeStub);
90
-		$routeStub = str_replace('{{enum}}', $this->replaceEnum($modelData), $routeStub);
91
-
92
-		return $routeStub;
93
-	}
94
-
95
-	/**
96
-	 * Replace the reverse relationships.
97
-	 *
98
-	 * @param $this->modelData
99
-	 *
100
-	 * @return string functions
101
-	 */
102
-	public function replaceReverseRelationships($modelData)
103
-	{
104
-		$functions = '';
105
-
106
-		foreach ($modelData->reverseRelationships as $relationship)
107
-		{
108
-			if ($relationship)
109
-			{
110
-				$functionName = '';
111
-				if ($relationship->type == "hasOne")
112
-					$functionName = strtolower($relationship->modelName);
113
-				elseif ($relationship->type == "belongsToMany") 
114
-					$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
115
-				else 
116
-					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
117
-
118
-				$method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n";
119
-				$method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
120
-				$method = str_replace('{{function_name}}', $functionName, $method);
121
-				$method = str_replace('{{resource}}', $modelData->modelName, $method);
122
-
123
-				$functions .= $method;
124
-			}
125
-		}
126
-
127
-		return $functions;
128
-	}
129
-
130
-	/**
131
-	 * Replace the enum.
132
-	 *
133
-	 * @param $this->modelData
134
-	 *
135
-	 * @return string functions
136
-	 */
137
-	public function replaceEnum($modelData)
138
-	{
139
-		$functions = '';
140
-
141
-		foreach ($modelData->fields as $field)
142
-		{
143
-			if ($field->type->db == "enum")
144
-			{
145
-				$method = "\tRoute::get('{{resource_lw}}/{{field_name}}', '{{resource}}Controller@get{{field_name_uc}}Options');\n";
146
-				$method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
147
-				$method = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method);
148
-				$method = str_replace('{{field_name}}', $field->name, $method);
149
-				$method = str_replace('{{resource}}', $modelData->modelName, $method);
150
-
151
-				$functions .= $method;
152
-			}
153
-		}
154
-
155
-		return $functions;
156
-	}
157
-
158
-
159
-	/**
160
-	 * Replace compiled routes.
161
-	 *
162
-	 * @param $compiledRoutes
163
-	 *
164
-	 * @return $this
165
-	 */
166
-	private function replaceRoutes($compiledRoutes)
167
-	{
168
-		$this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub);
169
-
170
-		return $this;
171
-	}
87
+        $routeStub = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $this->stubResource);
88
+        $routeStub = str_replace('{{resource}}', $modelData->modelName, $routeStub);
89
+        $routeStub = str_replace('{{reverseRelationships}}', $this->replaceReverseRelationships($modelData), $routeStub);
90
+        $routeStub = str_replace('{{enum}}', $this->replaceEnum($modelData), $routeStub);
91
+
92
+        return $routeStub;
93
+    }
94
+
95
+    /**
96
+     * Replace the reverse relationships.
97
+     *
98
+     * @param $this->modelData
99
+     *
100
+     * @return string functions
101
+     */
102
+    public function replaceReverseRelationships($modelData)
103
+    {
104
+        $functions = '';
105
+
106
+        foreach ($modelData->reverseRelationships as $relationship)
107
+        {
108
+            if ($relationship)
109
+            {
110
+                $functionName = '';
111
+                if ($relationship->type == "hasOne")
112
+                    $functionName = strtolower($relationship->modelName);
113
+                elseif ($relationship->type == "belongsToMany") 
114
+                    $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
115
+                else 
116
+                    $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
117
+
118
+                $method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n";
119
+                $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
120
+                $method = str_replace('{{function_name}}', $functionName, $method);
121
+                $method = str_replace('{{resource}}', $modelData->modelName, $method);
122
+
123
+                $functions .= $method;
124
+            }
125
+        }
126
+
127
+        return $functions;
128
+    }
129
+
130
+    /**
131
+     * Replace the enum.
132
+     *
133
+     * @param $this->modelData
134
+     *
135
+     * @return string functions
136
+     */
137
+    public function replaceEnum($modelData)
138
+    {
139
+        $functions = '';
140
+
141
+        foreach ($modelData->fields as $field)
142
+        {
143
+            if ($field->type->db == "enum")
144
+            {
145
+                $method = "\tRoute::get('{{resource_lw}}/{{field_name}}', '{{resource}}Controller@get{{field_name_uc}}Options');\n";
146
+                $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
147
+                $method = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method);
148
+                $method = str_replace('{{field_name}}', $field->name, $method);
149
+                $method = str_replace('{{resource}}', $modelData->modelName, $method);
150
+
151
+                $functions .= $method;
152
+            }
153
+        }
154
+
155
+        return $functions;
156
+    }
157
+
158
+
159
+    /**
160
+     * Replace compiled routes.
161
+     *
162
+     * @param $compiledRoutes
163
+     *
164
+     * @return $this
165
+     */
166
+    private function replaceRoutes($compiledRoutes)
167
+    {
168
+        $this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub);
169
+
170
+        return $this;
171
+    }
172 172
 
173 173
 	
174 174
 }
Please login to merge, or discard this patch.
stubs/Api/Routes.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -8,13 +8,13 @@  discard block
 block discarded – undo
8 8
 Route::group(['prefix' => '{{route_prefix}}', 'middleware' => 'cors'], function ()
9 9
 {
10 10
 
11
-	Route::get('dashboard', function ()
12
-	{
13
-		return view('dashboard');
14
-	});
11
+    Route::get('dashboard', function ()
12
+    {
13
+        return view('dashboard');
14
+    });
15 15
 
16
-	Route::match(['post'], 'upload', 'FileController@upload')->middleware('cors');
17
-	Route::get('upload', 'FileController@upload');
16
+    Route::match(['post'], 'upload', 'FileController@upload')->middleware('cors');
17
+    Route::get('upload', 'FileController@upload');
18 18
 	
19 19
 {{routes}}
20 20
 });
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 # todo fix in the correct manner
23 23
 // font fix issues
24 24
 Route::get('/styles/ui-grid.woff', function(){
25
-	return file_get_contents(base_path('public').'/fonts/ui-grid.woff');
25
+    return file_get_contents(base_path('public').'/fonts/ui-grid.woff');
26 26
 });
27 27
 
28 28
 Route::get('/styles/ui-grid.ttf', function(){
29
-	return file_get_contents(base_path('public').'/fonts/ui-grid.ttf');
29
+    return file_get_contents(base_path('public').'/fonts/ui-grid.ttf');
30 30
 });
31 31
 
32 32
 // other routes point for the dist html file
33 33
 Route::any('{any}', function(){
34
-	return file_get_contents(base_path('public').'/index.html');
34
+    return file_get_contents(base_path('public').'/index.html');
35 35
 })->where('any', '.*');
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
stubs/Api/Controller/FileController.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -15,56 +15,56 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
stubs/Api/Model/Model.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -13,209 +13,209 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
stubs/Api/Model/FileModel.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
stubs/Api/Migration.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -5,21 +5,21 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
stubs/Api/Controller/Controller.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -14,130 +14,130 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.