From 89ebf97fa032539425dcced42f6e36c1e3ca57f1 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Tue, 5 Jun 2018 12:54:29 +1200 Subject: [PATCH] added some repository and updated controller --- resources/assets/js/app.js | 3 +- resources/views/auth/login.blade.php | 119 +++++++------- .../views/auth/passwords/email.blade.php | 40 +++-- .../views/auth/passwords/reset.blade.php | 152 ++++++++++-------- .../Controllers/ConfigurationController.php | 20 ++- src/Http/Controllers/DashboardController.php | 15 +- src/Http/Controllers/MenuController.php | 44 +++-- src/Http/Controllers/OrderController.php | 14 +- src/Http/Controllers/PageController.php | 15 +- .../Controllers/ResetPasswordController.php | 4 +- src/Http/Controllers/RoleController.php | 19 ++- src/Models/Contracts/MenuInterface.php | 58 +++++++ src/Models/Contracts/PageInterface.php | 43 +++++ src/Models/Contracts/RoleInterface.php | 43 +++++ src/Models/Repository/MenuRepository.php | 100 ++++++++++++ src/Models/Repository/PageRepository.php | 60 +++++++ src/Models/Repository/RoleRepository.php | 59 +++++++ src/Provider.php | 5 + 18 files changed, 635 insertions(+), 178 deletions(-) create mode 100644 src/Models/Contracts/MenuInterface.php create mode 100644 src/Models/Contracts/PageInterface.php create mode 100644 src/Models/Contracts/RoleInterface.php create mode 100644 src/Models/Repository/MenuRepository.php create mode 100644 src/Models/Repository/PageRepository.php create mode 100644 src/Models/Repository/RoleRepository.php diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index bc8d268..7f4a113 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -22,7 +22,7 @@ require('summernote'); require('pc-bootstrap4-datetimepicker'); require('chartjs'); require('jquery-sortable'); - +window.Vue = require('vue/dist/vue'); window.axios = require('axios'); window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; @@ -34,3 +34,4 @@ if (token) { } else { console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); } + diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index a54c8fa..b72bbbf 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -22,82 +22,77 @@ ?> - -
+ +
-
-
- -
- {{ __('avored-ecommerce::lang.admin-login-card-title') }} -
-
- -
- {{ csrf_field() }} - - @include('avored-ecommerce::forms.text', - ['name' => 'email', - 'label' => __('avored-ecommerce::lang.admin-email-label') - ]) - @include('avored-ecommerce::forms.password',[ - 'name' => 'password', - 'label' => __('avored-ecommerce::lang.admin-password-label') - ]) - -
- - - - - {{ __('avored-ecommerce::lang.admin-login-forget-password-link') }} - -
- -
+
+
+
+ +
+ {{ __('avored-ecommerce::lang.admin-login-card-title') }} +
+
+ +
+ @csrf + + +
+ + + +
+
+ + +
+ +
+ + + + + {{ __('avored-ecommerce::lang.admin-login-forget-password-link') }} + +
+ +
+
+
-
-
+
+ +
- + diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php index 7c6686f..7b893d1 100644 --- a/resources/views/auth/passwords/email.blade.php +++ b/resources/views/auth/passwords/email.blade.php @@ -23,9 +23,10 @@ -
-
-
+
+
+
+
Reset Password
@@ -37,14 +38,12 @@
- {{ csrf_field() }} + action="{{ route('admin.password.reset.token') }}"> + @csrf
- - - @if ($errors->has('email')) @@ -57,7 +56,7 @@
- @@ -68,11 +67,34 @@
+
+ +
+ + diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php index e6fe8ee..f80a12d 100644 --- a/resources/views/auth/passwords/reset.blade.php +++ b/resources/views/auth/passwords/reset.blade.php @@ -22,79 +22,99 @@ ?> - -
-
-
-
-
Reset Password
- -
-
- - {{ csrf_field() }} - - - -
- - - - - - @if ($errors->has('email')) - - {{ $errors->first('email') }} - - @endif - -
- -
- - - - - - @if ($errors->has('password')) - - {{ $errors->first('password') }} - - @endif - -
- -
- - - - - @if ($errors->has('password_confirmation')) - - {{ $errors->first('password_confirmation') }} - - @endif - -
- -
- - - -
- + +
+
+
+
+
+
Reset Password
+ +
+
+
+ @csrf + +
+ + + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif + +
+ +
+ + + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif + +
+ +
+ + + + @if ($errors->has('password_confirmation')) + + {{ $errors->first('password_confirmation') }} + + @endif + +
+ +
+ + +
+
+
+
+ +
+ + diff --git a/src/Http/Controllers/ConfigurationController.php b/src/Http/Controllers/ConfigurationController.php index 5435653..b790206 100644 --- a/src/Http/Controllers/ConfigurationController.php +++ b/src/Http/Controllers/ConfigurationController.php @@ -6,9 +6,22 @@ use Illuminate\Http\Request; use AvoRed\Ecommerce\Models\Database\Page; use AvoRed\Framework\Models\Database\Configuration as Model; +use AvoRed\Framework\Models\Contracts\ConfigurationInterface; class ConfigurationController extends Controller { + + /** + * + * @var \AvoRed\Framework\Models\Repository\ConfigurationRepository + */ + protected $repository; + + public function __construct(ConfigurationInterface $repository) + { + $this->repository = $repository; + } + /** * Show the application dashboard. * @@ -34,18 +47,19 @@ public function index() public function store(Request $request) { foreach ($request->except(['_token', '_method']) as $key => $value) { - $configModel = Model::whereConfigurationKey($key)->first(); + + $configModel = $this->repository->findByKey($key); if ($configModel->configuration_value == $value) { continue; } if (null === $configModel) { - + $data['configuration_key'] = $key; $data['configuration_value'] = $value; - Model::create($data); + $this->repository->create($data); } else { $configModel->update(['configuration_value' => $value]); } diff --git a/src/Http/Controllers/DashboardController.php b/src/Http/Controllers/DashboardController.php index 295884e..b95cfa6 100644 --- a/src/Http/Controllers/DashboardController.php +++ b/src/Http/Controllers/DashboardController.php @@ -3,10 +3,21 @@ namespace AvoRed\Ecommerce\Http\Controllers; use AvoRed\Framework\Models\Database\Configuration; -use AvoRed\Framework\Models\Database\Order; +use AvoRed\Framework\Models\Contracts\OrderInterface; class DashboardController extends Controller { + /** + * + * @var \AvoRed\Framework\Models\Repository\OrderRepository + */ + protected $repository; + + public function __construct(OrderInterface $repository) + { + $this->repository = $repository; + } + /** * Show the application dashboard. * @@ -17,7 +28,7 @@ public function index() $value = Configuration::getConfiguration('avored_user_total'); $totalRegisteredUser = (null === $value) ? 0 : $value; - $totalOrder = Order::all()->count(); + $totalOrder = $this->repository->all()->count(); return view('avored-ecommerce::home') ->with('totalRegisteredUser', $totalRegisteredUser) diff --git a/src/Http/Controllers/MenuController.php b/src/Http/Controllers/MenuController.php index adddc27..88ecaa9 100644 --- a/src/Http/Controllers/MenuController.php +++ b/src/Http/Controllers/MenuController.php @@ -6,10 +6,24 @@ use AvoRed\Framework\Models\Database\Category; use Illuminate\Http\Request; use AvoRed\Framework\Menu\Facade as MenuFacade; +use AvoRed\Ecommerce\Models\Repository\MenuRepository; +use AvoRed\Ecommerce\Models\Contracts\MenuInterface; class MenuController extends Controller { + /** + * + * @var \AvoRed\Ecommerce\Models\Repository\MenuRepository + */ + protected $repository; + + public function __construct(MenuInterface $repository) + { + $this->repository = $repository; + } + + /** * Display a listing of the resource. * @@ -19,7 +33,7 @@ public function index() { $frontMenus = MenuFacade::all(); $categories = Category::all(); - $menus = Menu::whereParentId(null)->orWhere('parent_id','=',0)->get(); + $menus = $this->repository->parentsAll(); return view('avored-ecommerce::menu.index') ->with('categories', $categories) @@ -34,32 +48,12 @@ public function index() */ public function store(Request $request) { - $menuJson = $request->get('menu_json'); - $menuArray = json_decode($menuJson); - Menu::truncate(); - - foreach ($menuArray as $menus) { - $this->_saveMenu($menus); - } + $menuJson = $request->get('menu_json'); + $menuArray = json_decode($menuJson); + + $this->repository->truncateAndCreateMenus($menuArray); return redirect()->route('admin.menu.index') ->with('notificationText','Menu Save Successfully!!'); } - - private function _saveMenu($menus, $parentId = null) { - - foreach ($menus as $menu) { - - $menuModel = Menu::create(['name' => $menu->name, - 'route' => $menu->route, - 'params' => $menu->params, - 'parent_id' => $parentId]); - - if(isset($menu->children) && count($menu->children[0]) >0) { - $this->_saveMenu($menu->children[0], $menuModel->id); - } - - } - } - } diff --git a/src/Http/Controllers/OrderController.php b/src/Http/Controllers/OrderController.php index 39acb2a..d18262e 100644 --- a/src/Http/Controllers/OrderController.php +++ b/src/Http/Controllers/OrderController.php @@ -12,10 +12,22 @@ use AvoRed\Ecommerce\Mail\UpdateOrderStatusMail; use AvoRed\Ecommerce\DataGrid\Order as OrderGrid; use AvoRed\Ecommerce\Http\Requests\UpdateOrderStatusRequest; +use AvoRed\Framework\Models\Contracts\OrderInterface; class OrderController extends Controller { + /** + * + * @var \AvoRed\Framework\Models\Repository\OrderRepository + */ + protected $repository; + + public function __construct(OrderInterface $repository) + { + $this->repository = $repository; + } + /** * Display a listing of the resource. * @@ -23,7 +35,7 @@ class OrderController extends Controller */ public function index() { - $orderGrid = new OrderGrid(Model::query()->orderBy('id', 'desc')); + $orderGrid = new OrderGrid($this->repository->query()->orderBy('id', 'desc')); return view('avored-ecommerce::order.index')->with('dataGrid', $orderGrid->dataGrid); } diff --git a/src/Http/Controllers/PageController.php b/src/Http/Controllers/PageController.php index 6a02187..71fa966 100644 --- a/src/Http/Controllers/PageController.php +++ b/src/Http/Controllers/PageController.php @@ -6,9 +6,20 @@ use AvoRed\Framework\Widget\Facade as Widget; use AvoRed\Ecommerce\DataGrid\Page as PageGrid; use AvoRed\Ecommerce\Http\Requests\PageRequest; +use AvoRed\Ecommerce\Models\Contracts\PageInterface; class PageController extends Controller { + /** + * + * @var \AvoRed\Framework\Models\Repository\PageRepository + */ + protected $repository; + + public function __construct(PageInterface $repository) + { + $this->repository = $repository; + } /** * Display a listing of the Page. @@ -17,7 +28,7 @@ class PageController extends Controller */ public function index() { - $pageGrid = new PageGrid(Model::query()->orderBy('id', 'desc')); + $pageGrid = new PageGrid($this->repository->query()->orderBy('id', 'desc')); return view('avored-ecommerce::page.index')->with('dataGrid', $pageGrid->dataGrid); } @@ -44,7 +55,7 @@ public function create() */ public function store(PageRequest $request) { - Model::create($request->all()); + $this->repository->create($request->all()); return redirect()->route('admin.page.index'); } diff --git a/src/Http/Controllers/ResetPasswordController.php b/src/Http/Controllers/ResetPasswordController.php index 89a338c..eef1493 100644 --- a/src/Http/Controllers/ResetPasswordController.php +++ b/src/Http/Controllers/ResetPasswordController.php @@ -7,7 +7,6 @@ use Illuminate\Support\Facades\Password; use Illuminate\Foundation\Auth\ResetsPasswords; - class ResetPasswordController extends Controller { /* @@ -62,7 +61,8 @@ protected function guard() public function showResetForm(Request $request, $token = null) { return view('avored-ecommerce::auth.passwords.reset') - ->with(['token' => $token, 'email' => $request->email] + ->with( + ['token' => $token, 'email' => $request->email] ); } } diff --git a/src/Http/Controllers/RoleController.php b/src/Http/Controllers/RoleController.php index 7ed5600..37e3984 100644 --- a/src/Http/Controllers/RoleController.php +++ b/src/Http/Controllers/RoleController.php @@ -7,10 +7,21 @@ use AvoRed\Ecommerce\Http\Requests\RoleRequst; use AvoRed\Ecommerce\Models\Database\Permission; use AvoRed\Framework\DataGrid\Facade as DataGrid; +use AvoRed\Ecommerce\Models\Contracts\RoleInterface; class RoleController extends Controller { - + /** + * + * @var \AvoRed\Ecommerce\Models\Repository\RoleRepository + */ + protected $repository; + + public function __construct(RoleInterface $repository) + { + $this->repository = $repository; + } + /** * Display a listing of the resource. * @@ -18,7 +29,7 @@ class RoleController extends Controller */ public function index() { - $roleGrid = new Role(Model::query()); + $roleGrid = new Role($this->repository->query()); return view('avored-ecommerce::role.index')->with('dataGrid', $roleGrid->dataGrid); } @@ -43,7 +54,7 @@ public function create() public function store(RoleRequst $request) { try { - $role = Model::create($request->all()); + $role = $this->repository->create($request->all()); $this->_saveRolePermissions($request, $role); } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; @@ -111,9 +122,7 @@ private function _saveRolePermissions($request, $role) $permissionIds = []; if (count($request->get('permissions')) > 0) { - foreach ($request->get('permissions') as $key => $value) { - if ($value != 1) { continue; } diff --git a/src/Models/Contracts/MenuInterface.php b/src/Models/Contracts/MenuInterface.php new file mode 100644 index 0000000..9ba1ca6 --- /dev/null +++ b/src/Models/Contracts/MenuInterface.php @@ -0,0 +1,58 @@ +orWhere('parent_id','=',0)->get(); + } + + /** + * Get all Menu + * + * @return \Illuminate\Database\Eloquent\Collection + */ + public function all() + { + return Menu::all(); + } + + /** + * Paginate Menu + * + * @return \Illuminate\Pagination\LengthAwarePaginator + */ + public function paginate($noOfItem = 10) + { + return Menu::paginate($noOfItem); + } + + /** + * Get an Menu Query Builder Object + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function query() + { + return Menu::query(); + } + + /** + * Find an Menu Query + * + * @return \AvoRed\Ecommerce\Models\Menu + */ + public function create($data) + { + return Menu::create($data); + } + + /** + * + * @param array $menus + * @return \AvoRed\Ecommerce\Models\Repository\MenuRepository + */ + public function truncateAndCreateMenus($menus) + { + + Menu::truncate(); + foreach ($menus as $menu) { + $this->_saveMenu($menu); + } + + } + + private function _saveMenu($menus, $parentId = null) { + + foreach ($menus as $menu) { + $menuModel = $this->create(['name' => $menu->name, + 'route' => $menu->route, + 'params' => $menu->params, + 'parent_id' => $parentId]); + + if(isset($menu->children) && count($menu->children[0]) >0) { + $this->_saveMenu($menu->children[0], $menuModel->id); + } + + } +} +} diff --git a/src/Models/Repository/PageRepository.php b/src/Models/Repository/PageRepository.php new file mode 100644 index 0000000..aee88f7 --- /dev/null +++ b/src/Models/Repository/PageRepository.php @@ -0,0 +1,60 @@ +app->bind(AdminUserInterface::class,AdminUserRepository::class); + $this->app->bind(MenuInterface::class,MenuRepository::class); } }