From 1bc9e90ac6ed28359c43a33717549e284945b06e Mon Sep 17 00:00:00 2001 From: howdu Date: Tue, 27 Oct 2020 09:53:00 +0000 Subject: [PATCH] Prevent errors when running route:list Trying to access array offset on value of type null In ResourceController.php line 48 --- .../Controllers/Shop/InvoiceController.php | 4 +++- .../Controllers/Shop/ResourceController.php | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/Webkul/API/Http/Controllers/Shop/InvoiceController.php b/packages/Webkul/API/Http/Controllers/Shop/InvoiceController.php index d20a9fffb..4efcb0a19 100644 --- a/packages/Webkul/API/Http/Controllers/Shop/InvoiceController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/InvoiceController.php @@ -43,7 +43,9 @@ class InvoiceController extends Controller $this->middleware('auth:' . $this->guard); } - $this->repository = app($this->_config['repository']); + if ($this->_config) { + $this->repository = app($this->_config['repository']); + } } /** diff --git a/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php b/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php index e4861136d..1bc627003 100644 --- a/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php @@ -12,7 +12,7 @@ class ResourceController extends Controller * @var array */ protected $guard; - + /** * Contains route related configuration * @@ -45,7 +45,9 @@ class ResourceController extends Controller $this->middleware('auth:' . $this->guard); } - $this->repository = app($this->_config['repository']); + if ($this->_config) { + $this->repository = app($this->_config['repository']); + } } /** @@ -58,8 +60,8 @@ class ResourceController extends Controller $query = $this->repository->scopeQuery(function($query) { if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) { $query = $query->where('customer_id', auth()->user()->id ); - } - + } + foreach (request()->except(['page', 'limit', 'pagination', 'sort', 'order', 'token']) as $input => $value) { $query = $query->whereIn($input, array_map('trim', explode(',', $value))); } @@ -89,11 +91,11 @@ class ResourceController extends Controller * @return \Illuminate\Http\Response */ public function get($id) - { - $query = isset($this->_config['authorization_required']) && $this->_config['authorization_required'] ? - $this->repository->where('customer_id', auth()->user()->id)->findOrFail($id) : + { + $query = isset($this->_config['authorization_required']) && $this->_config['authorization_required'] ? + $this->repository->where('customer_id', auth()->user()->id)->findOrFail($id) : $this->repository->findOrFail($id); - + return new $this->_config['resource']($query); } @@ -108,7 +110,7 @@ class ResourceController extends Controller $wishlistProduct = $this->repository->findOrFail($id); $this->repository->delete($id); - + return response()->json([ 'message' => 'Item removed successfully.', ]);