diff --git a/app/Console/Commands/stubs/controller.stub b/app/Console/Commands/stubs/controller.stub index d22b55a494c0..c7a9c991746b 100755 --- a/app/Console/Commands/stubs/controller.stub +++ b/app/Console/Commands/stubs/controller.stub @@ -126,4 +126,17 @@ class $CLASS$ extends BaseController public function destroy() { } + + /** + * Update multiple resources + */ + public function bulk() + { + $action = request()->input('action'); + $ids = request()->input('public_id') ?: request()->input('ids'); + $count = $this->$LOWER_NAME$Repo->bulk($ids, $action); + + return redirect()->to('$LOWER_NAME$') + ->with('message', trans('texts.' . $action . '_$LOWER_NAME$_complete')); + } } diff --git a/app/Console/Commands/stubs/repository.stub b/app/Console/Commands/stubs/repository.stub index 6bc25b42cf10..0fecf60bf46e 100644 --- a/app/Console/Commands/stubs/repository.stub +++ b/app/Console/Commands/stubs/repository.stub @@ -12,7 +12,7 @@ class $STUDLY_NAME$Repository extends BaseRepository { public function getClassName() { - return '$NAMESPACE$\$STUDLY_NAME$'; + return 'Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$'; } public function find($filter = null, $userId = false) diff --git a/app/Console/Commands/stubs/routes.stub b/app/Console/Commands/stubs/routes.stub index 85fb4a8e9271..6860ed2290ef 100755 --- a/app/Console/Commands/stubs/routes.stub +++ b/app/Console/Commands/stubs/routes.stub @@ -3,5 +3,6 @@ Route::group(['middleware' => 'auth', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function() { Route::resource('$LOWER_NAME$', '$STUDLY_NAME$Controller'); + Route::post('$LOWER_NAME$/bulk', '$STUDLY_NAME$Controller@bulk'); Route::get('api/$LOWER_NAME$', '$STUDLY_NAME$Controller@datatable'); }); diff --git a/app/Ninja/Repositories/BaseRepository.php b/app/Ninja/Repositories/BaseRepository.php index 2f81194d657b..71d8c1b9fbdc 100644 --- a/app/Ninja/Repositories/BaseRepository.php +++ b/app/Ninja/Repositories/BaseRepository.php @@ -1,5 +1,6 @@ findByPublicIdsWithTrashed($ids); + + foreach ($entities as $entity) { + if (Auth::user()->can('edit', $entity)) { + $this->$action($entity); + } + } + + return count($entities); + } + /** * @param $ids * @return mixed