@@ -51,7 +51,6 @@ |
||
51 | 51 | /** |
52 | 52 | * Execute the console command. |
53 | 53 | * |
54 | - |
|
55 | 54 | */ |
56 | 55 | public function handle() |
57 | 56 | { |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function handle() |
57 | 57 | { |
58 | - $file = preg_split( " (/|\\\\) ", (string)$this->argument('name')) ?? []; |
|
58 | + $file = preg_split(" (/|\\\\) ", (string) $this->argument('name')) ?? []; |
|
59 | 59 | $this->repoName = $file[count($file) - 1]; |
60 | - if($this->option('only-view')) |
|
60 | + if ($this->option('only-view')) |
|
61 | 61 | { |
62 | 62 | $this->makeViewsAndLanguage(); |
63 | 63 | return null; |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | unset($file[count($file) - 1]); |
72 | 72 | $path = implode("\\", $file); |
73 | 73 | |
74 | - $model= str_plural(\Config::get('repository.model')); |
|
75 | - $interface= str_plural(\Config::get('repository.interface')); |
|
76 | - $repository= str_plural(\Config::get('repository.repository')); |
|
74 | + $model = str_plural(\Config::get('repository.model')); |
|
75 | + $interface = str_plural(\Config::get('repository.interface')); |
|
76 | + $repository = str_plural(\Config::get('repository.repository')); |
|
77 | 77 | |
78 | 78 | $this->generate($path, \Config::get('repository.controllers_folder'), 'Controller'); |
79 | 79 | $this->generate($path, $model, 'Entity'); |
@@ -81,19 +81,19 @@ discard block |
||
81 | 81 | $this->generate($path, $interface, 'Interface'); |
82 | 82 | $this->generate($path, $repository, 'Repository'); |
83 | 83 | |
84 | - File::append(\Config::get('repository.route_path') . '/web.php', "\n" . 'Route::resource(\'' . strtolower(str_plural($this->repoName)) . "', '".$path."\\".$this->repoName."Controller');"); |
|
84 | + File::append(\Config::get('repository.route_path') . '/web.php', "\n" . 'Route::resource(\'' . strtolower(str_plural($this->repoName)) . "', '" . $path . "\\" . $this->repoName . "Controller');"); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | function makeViewsAndLanguage() |
88 | 88 | { |
89 | 89 | foreach (\Config::get('repository.languages') as $lang) |
90 | 90 | { |
91 | - $this->generate(lcfirst($this->repoName),\Config::get('repository.lang_path')."/{$lang}" , 'lang'); |
|
91 | + $this->generate(lcfirst($this->repoName), \Config::get('repository.lang_path') . "/{$lang}", 'lang'); |
|
92 | 92 | } |
93 | - $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'create'); |
|
94 | - $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'edit'); |
|
95 | - $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'index'); |
|
96 | - $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'show'); |
|
93 | + $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'create'); |
|
94 | + $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'edit'); |
|
95 | + $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'index'); |
|
96 | + $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'show'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | { |
118 | 118 | $content = $this->getStub($type); |
119 | 119 | |
120 | - if($content === false) |
|
120 | + if ($content === false) |
|
121 | 121 | { |
122 | - echo 'file '.$type.".stub is not exist !"; |
|
122 | + echo 'file ' . $type . ".stub is not exist !"; |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
@@ -135,20 +135,20 @@ discard block |
||
135 | 135 | $this->repoName, |
136 | 136 | str_plural($folder), |
137 | 137 | $path, |
138 | - str_plural(\Config::get('repository.model','Entity')), |
|
139 | - str_plural(\Config::get('repository.interface','Interface')), |
|
138 | + str_plural(\Config::get('repository.model', 'Entity')), |
|
139 | + str_plural(\Config::get('repository.interface', 'Interface')), |
|
140 | 140 | ], |
141 | 141 | $this->getStub($type) |
142 | 142 | ); |
143 | 143 | |
144 | - $folder = str_replace('\\','/',$folder); |
|
145 | - $path = str_replace('\\','/',$path); |
|
144 | + $folder = str_replace('\\', '/', $folder); |
|
145 | + $path = str_replace('\\', '/', $path); |
|
146 | 146 | |
147 | 147 | switch ($type) |
148 | 148 | { |
149 | 149 | case 'Entity': |
150 | 150 | $filePath = $this->getFolderOrCreate(\Config::get('repository.app_path') . "/{$folder}/{$path}"); |
151 | - $filePath = rtrim($filePath,'/'); |
|
151 | + $filePath = rtrim($filePath, '/'); |
|
152 | 152 | $filePath .= "/"; |
153 | 153 | file_put_contents($filePath . "{$this->repoName}.php", $template); |
154 | 154 | break; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | case 'Repository': |
158 | 158 | case 'Interface': |
159 | 159 | $filePath = $this->getFolderOrCreate(\Config::get('repository.app_path') . "/{$folder}/{$path}"); |
160 | - $filePath = rtrim($filePath,'/'); |
|
160 | + $filePath = rtrim($filePath, '/'); |
|
161 | 161 | $filePath .= "/"; |
162 | 162 | file_put_contents($filePath . "{$this->repoName}{$type}.php", $template); |
163 | 163 | break; |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | case 'edit': |
166 | 166 | case 'index': |
167 | 167 | case 'show': |
168 | - $filePath = $this->getFolderOrCreate($folder."/".str_plural($path))."/"; |
|
168 | + $filePath = $this->getFolderOrCreate($folder . "/" . str_plural($path)) . "/"; |
|
169 | 169 | $repoName = lcfirst($type); |
170 | - file_put_contents($filePath . $repoName.".blade.php", $template); |
|
170 | + file_put_contents($filePath . $repoName . ".blade.php", $template); |
|
171 | 171 | break; |
172 | 172 | default: |
173 | - $filePath = $this->getFolderOrCreate($folder)."/"; |
|
173 | + $filePath = $this->getFolderOrCreate($folder) . "/"; |
|
174 | 174 | $repoName = lcfirst($this->repoName); |
175 | - file_put_contents($filePath . $repoName.".php", $template); |
|
175 | + file_put_contents($filePath . $repoName . ".php", $template); |
|
176 | 176 | } |
177 | 177 | return true; |
178 | 178 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | protected function failedValidation(Validator $validator) |
30 | 30 | { |
31 | 31 | |
32 | - if (strpos($this->path(),'api') !== false) { |
|
32 | + if (strpos($this->path(), 'api') !== false) { |
|
33 | 33 | $errors = (new ValidationException($validator))->errors(); |
34 | 34 | throw new HttpResponseException(response()->json(['success' => false, 'errors' => $errors, |
35 | 35 | ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | parent::failedValidation($validator); |
38 | 38 | } |
39 | 39 | |
40 | - public function rules(){ |
|
41 | - \App::setLocale($this->header('Language','en')); |
|
40 | + public function rules() { |
|
41 | + \App::setLocale($this->header('Language', 'en')); |
|
42 | 42 | } |
43 | 43 | } |
@@ -344,9 +344,10 @@ |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | if ($entity) { |
347 | - if($appendEntity) |
|
348 | - return response()->json( ['status' => true, 'message' => __('messages.success'), 'data' => $entity], |
|
347 | + if($appendEntity) { |
|
348 | + return response()->json( ['status' => true, 'message' => __('messages.success'), 'data' => $entity], |
|
349 | 349 | JsonResponse::HTTP_OK); |
350 | + } |
|
350 | 351 | return response()->json(null, JsonResponse::HTTP_NO_CONTENT); |
351 | 352 | } |
352 | 353 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $this->breadcrumbs = new Collection(); |
59 | 59 | |
60 | 60 | $language = $request->header('Language', 'en'); |
61 | - if (! in_array($language, \Config::get('app.locales', []))) { |
|
61 | + if (!in_array($language, \Config::get('app.locales', []))) { |
|
62 | 62 | $language = 'en'; |
63 | 63 | } |
64 | 64 | $limit = $request->get('limit', 10); |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | $this->interface = $interface; |
82 | 82 | $this->isAPI = $request->expectsJson(); |
83 | 83 | |
84 | - if (! $this->isAPI) { |
|
84 | + if (!$this->isAPI) { |
|
85 | 85 | $this->breadcrumbs = new Collection(); |
86 | 86 | $this->search = new Collection(); |
87 | - \View::share('pageTitle', $this->pageTitle.' | '.\Config::get('app.name')); |
|
87 | + \View::share('pageTitle', $this->pageTitle . ' | ' . \Config::get('app.name')); |
|
88 | 88 | \View::share('breadcrumbs', $this->breadcrumbs); |
89 | 89 | \View::share('menu', $this->menu); |
90 | 90 | \View::share('search', $this->search); |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | public function index() |
103 | 103 | { |
104 | 104 | $data = $this->interface->simplePaginate($this->limit, $this->request->all()); |
105 | - if (! $this->isAPI) { |
|
106 | - \View::share('pageTitle', 'List '.$this->pageTitle.' | '.\Config::get('app.name')); |
|
105 | + if (!$this->isAPI) { |
|
106 | + \View::share('pageTitle', 'List ' . $this->pageTitle . ' | ' . \Config::get('app.name')); |
|
107 | 107 | $this->breadcrumbs->put('index', [ |
108 | 108 | 'link' => $this->routeIndex, |
109 | 109 | 'text' => $this->pageTitle, |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function create() |
133 | 133 | { |
134 | - if (! $this->isAPI) { |
|
135 | - \View::share('pageTitle', 'Create '.$this->pageTitle.' | '.\Config::get('app.name')); |
|
134 | + if (!$this->isAPI) { |
|
135 | + \View::share('pageTitle', 'Create ' . $this->pageTitle . ' | ' . \Config::get('app.name')); |
|
136 | 136 | $this->breadcrumbs->put('create', [ |
137 | 137 | 'link' => $this->createRoute, |
138 | 138 | 'text' => trans('common/others.create'), |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | public function store() |
153 | 153 | { |
154 | 154 | $entity = $this->interface->create($this->request->except(['_token', '_method'])); |
155 | - return $this->makeResponse($entity,true); |
|
155 | + return $this->makeResponse($entity, true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | public function show($entityId) |
166 | 166 | { |
167 | 167 | $entity = $this->interface->find($entityId); |
168 | - if (! $this->isAPI) { |
|
169 | - if (! $entity) { |
|
168 | + if (!$this->isAPI) { |
|
169 | + if (!$entity) { |
|
170 | 170 | return \Redirect::to($this->routeIndex)->with('warning', __('messages.not_found')); |
171 | 171 | } |
172 | - \View::share('pageTitle', 'View '.$this->pageTitle.' | '.\Config::get('app.name')); |
|
172 | + \View::share('pageTitle', 'View ' . $this->pageTitle . ' | ' . \Config::get('app.name')); |
|
173 | 173 | $this->breadcrumbs->put('view', [ |
174 | 174 | 'link' => '', |
175 | 175 | 'text' => $entity->name ?? $entity->title ?? __('messages.view'), |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | return view($this->viewShow, $this->params) |
179 | 179 | ->with('entity', $entity); |
180 | 180 | } |
181 | - if (! $entity) { |
|
181 | + if (!$entity) { |
|
182 | 182 | return response()->json(null, JsonResponse::HTTP_NOT_FOUND); |
183 | 183 | } |
184 | 184 | |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | public function edit($entityId) |
199 | 199 | { |
200 | 200 | $entity = $this->interface->find($entityId); |
201 | - if (! $this->isAPI) { |
|
202 | - if (! $entity) { |
|
201 | + if (!$this->isAPI) { |
|
202 | + if (!$entity) { |
|
203 | 203 | return \Redirect::to($this->routeIndex)->with('warning', __('messages.not_found')); |
204 | 204 | } |
205 | 205 | $this->breadcrumbs->put('edit', [ |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | { |
226 | 226 | $entity = $this->interface->update($entityId, $this->request->except(['_token', '_method'])); |
227 | 227 | |
228 | - return $this->makeResponse($entity,true); |
|
228 | + return $this->makeResponse($entity, true); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return \Illuminate\Http\RedirectResponse |
281 | 281 | */ |
282 | - function makeResponse($entity,$appendEntity = false) |
|
282 | + function makeResponse($entity, $appendEntity = false) |
|
283 | 283 | { |
284 | - if (! $this->isAPI) { |
|
284 | + if (!$this->isAPI) { |
|
285 | 285 | if ($entity) { |
286 | 286 | return \Redirect::to($this->routeIndex)->with('message', __('messages.success')); |
287 | 287 | } |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | if ($entity) { |
297 | - if($appendEntity) |
|
298 | - return response()->json( ['status' => true, 'message' => __('messages.success'), 'data' => $entity], |
|
297 | + if ($appendEntity) |
|
298 | + return response()->json(['status' => true, 'message' => __('messages.success'), 'data' => $entity], |
|
299 | 299 | JsonResponse::HTTP_OK); |
300 | 300 | return response()->json(null, JsonResponse::HTTP_NO_CONTENT); |
301 | 301 | } |
@@ -26,16 +26,16 @@ |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | $this->publishes([ |
29 | - __DIR__.'/config' => realpath('config'), |
|
30 | - ],'repository-config'); |
|
29 | + __DIR__ . '/config' => realpath('config'), |
|
30 | + ], 'repository-config'); |
|
31 | 31 | |
32 | 32 | if ($this->app['config']->get('repository') === null) { |
33 | - $this->app['config']->set('repository', require __DIR__.'/config/repository.php'); |
|
33 | + $this->app['config']->set('repository', require __DIR__ . '/config/repository.php'); |
|
34 | 34 | } |
35 | - $this->mergeConfigFrom(__DIR__.'/config/repository.php', 'repository-config'); |
|
35 | + $this->mergeConfigFrom(__DIR__ . '/config/repository.php', 'repository-config'); |
|
36 | 36 | $this->publishes([ |
37 | - realpath(__DIR__ . '/../stubs') => \Config::get('repository.resources_path',realpath(__DIR__.'/../../../../resources/')), |
|
38 | - ],'repository-stub'); |
|
37 | + realpath(__DIR__ . '/../stubs') => \Config::get('repository.resources_path', realpath(__DIR__ . '/../../../../resources/')), |
|
38 | + ], 'repository-stub'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | parent::__construct($app); |
36 | 36 | |
37 | 37 | if ($this->app['config']->get('repository') === null) { |
38 | - $this->app['config']->set('repository', require __DIR__.'/config/repository.php'); |
|
38 | + $this->app['config']->set('repository', require __DIR__ . '/config/repository.php'); |
|
39 | 39 | } |
40 | - $interfaces= str_plural(Config::get('repository.interface')); |
|
41 | - $repositories= str_plural(Config::get('repository.repository')); |
|
42 | - $interface= Config::get('repository.interface'); |
|
43 | - $repository= Config::get('repository.repository'); |
|
40 | + $interfaces = str_plural(Config::get('repository.interface')); |
|
41 | + $repositories = str_plural(Config::get('repository.repository')); |
|
42 | + $interface = Config::get('repository.interface'); |
|
43 | + $repository = Config::get('repository.repository'); |
|
44 | 44 | |
45 | - $contractsFolder = Config::get('repository.app_path').'/'.$interfaces; |
|
45 | + $contractsFolder = Config::get('repository.app_path') . '/' . $interfaces; |
|
46 | 46 | |
47 | 47 | if ($contractsFolder) { |
48 | 48 | $directory = new \RecursiveDirectoryIterator($contractsFolder); |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | $regex = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); |
51 | 51 | foreach ($regex as $name => $value) { |
52 | 52 | |
53 | - $contract = strstr($name,'app/') ?: strstr($name,'app\\'); |
|
54 | - $contract = rtrim($contract,'.php'); |
|
53 | + $contract = strstr($name, 'app/') ?: strstr($name, 'app\\'); |
|
54 | + $contract = rtrim($contract, '.php'); |
|
55 | 55 | |
56 | 56 | $contractName = str_replace('/', '\\', ucfirst($contract)); |
57 | 57 | |
58 | 58 | $repositoryClass = str_replace($interfaces, $repositories, $contractName); |
59 | - $repositoryClass = str_replace([$interface,'Interface'], $repository, $repositoryClass); |
|
59 | + $repositoryClass = str_replace([$interface, 'Interface'], $repository, $repositoryClass); |
|
60 | 60 | |
61 | 61 | $this->providers[] = $contractName; |
62 | 62 | $this->bindings[$contractName] = $repositoryClass; |
@@ -6,11 +6,11 @@ |
||
6 | 6 | * Time: 09:58 am |
7 | 7 | */ |
8 | 8 | return [ |
9 | - 'app_path' => realpath(__DIR__.'/../app/'), |
|
9 | + 'app_path' => realpath(__DIR__ . '/../app/'), |
|
10 | 10 | 'route_path' => realpath('routes/'), |
11 | - 'resources_path' => realpath(__DIR__.'/../vendor/shamaseen/repository-generator/stubs'), |
|
12 | - 'stubs_path' => realpath('resources')."/stubs", |
|
13 | - 'lang_path' => realpath('resources')."/lang", |
|
11 | + 'resources_path' => realpath(__DIR__ . '/../vendor/shamaseen/repository-generator/stubs'), |
|
12 | + 'stubs_path' => realpath('resources') . "/stubs", |
|
13 | + 'lang_path' => realpath('resources') . "/lang", |
|
14 | 14 | |
15 | 15 | //relative to app path |
16 | 16 | 'interface' => 'Interface', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function filter($criteria = []) |
79 | 79 | { |
80 | - $criteria= $this->order($criteria); |
|
80 | + $criteria = $this->order($criteria); |
|
81 | 81 | |
82 | 82 | /** @var Entity $latest */ |
83 | 83 | $latest = $this->model->with($this->with); |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | |
88 | 88 | if (isset($criteria['search'])) { |
89 | 89 | foreach ($this->model->searchable as $method => $columns) { |
90 | - if(method_exists($this->model,$method)) |
|
90 | + if (method_exists($this->model, $method)) |
|
91 | 91 | { |
92 | - $latest->orWhereHas($method,function ($query) use ($criteria,$columns) |
|
92 | + $latest->orWhereHas($method, function($query) use ($criteria, $columns) |
|
93 | 93 | { |
94 | 94 | /** @var $query Builder */ |
95 | - $query->where(function ($query2) use($criteria,$columns){ |
|
95 | + $query->where(function($query2) use($criteria, $columns){ |
|
96 | 96 | /** @var $query2 Builder */ |
97 | 97 | foreach ((array) $columns as $column) |
98 | 98 | { |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return array |
126 | 126 | */ |
127 | - private function order($criteria=[]){ |
|
127 | + private function order($criteria = []) { |
|
128 | 128 | |
129 | 129 | if (isset($criteria['order'])) { |
130 | 130 | $this->order = $criteria['order']; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | { |
172 | 172 | $item = $this->model->findOrFail($entityId); |
173 | 173 | |
174 | - if($item->update($attributes)) |
|
174 | + if ($item->update($attributes)) |
|
175 | 175 | { |
176 | 176 | return $item; |
177 | 177 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function find($entityId = 0, $columns = ['*']) |
236 | 236 | { |
237 | - return $this->model->with($this->with)->find($entityId,$columns); |
|
237 | + return $this->model->with($this->with)->find($entityId, $columns); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function findOrFail($entityId = 0, $columns = ['*']) |
247 | 247 | { |
248 | - return $this->model->with($this->with)->findOrFail($entityId,$columns); |
|
248 | + return $this->model->with($this->with)->findOrFail($entityId, $columns); |
|
249 | 249 | } |
250 | 250 | /** |
251 | 251 | * @param array $filter |
@@ -100,9 +100,9 @@ |
||
100 | 100 | } |
101 | 101 | }); |
102 | 102 | }); |
103 | + } else { |
|
104 | + $latest->orWhere($columns, 'like', "%" . $criteria['search'] . "%", 'or'); |
|
103 | 105 | } |
104 | - else |
|
105 | - $latest->orWhere($columns, 'like', "%" . $criteria['search'] . "%", 'or'); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | unset($criteria['search']); |