diff --git a/app/Http/Controllers/Api/Auth/Users.php b/app/Http/Controllers/Api/Auth/Users.php index 3ab71a555..3f8d8f4b4 100644 --- a/app/Http/Controllers/Api/Auth/Users.php +++ b/app/Http/Controllers/Api/Auth/Users.php @@ -40,6 +40,10 @@ class Users extends ApiController $user = User::with('companies', 'permissions', 'roles')->where('email', $id)->first(); } + if (! $user instanceof User) { + return $this->errorInternal('No query results for model [' . User::class . '] ' . $id); + } + return new Resource($user); } diff --git a/app/Http/Controllers/Api/Banking/Accounts.php b/app/Http/Controllers/Api/Banking/Accounts.php index a1b6b982a..ef65f4d61 100644 --- a/app/Http/Controllers/Api/Banking/Accounts.php +++ b/app/Http/Controllers/Api/Banking/Accounts.php @@ -39,6 +39,10 @@ class Accounts extends ApiController $account = Account::where('number', $id)->first(); } + if (! $account instanceof Account) { + return $this->errorInternal('No query results for model [' . Account::class . '] ' . $id); + } + return new Resource($account); } diff --git a/app/Http/Controllers/Api/Common/Contacts.php b/app/Http/Controllers/Api/Common/Contacts.php index ad7799b84..f492806e6 100644 --- a/app/Http/Controllers/Api/Common/Contacts.php +++ b/app/Http/Controllers/Api/Common/Contacts.php @@ -42,6 +42,11 @@ class Contacts extends ApiController $contact = Contact::where('email', $id)->first(); } + if (! $contact instanceof Contact) { + //return $this->noContent(); + return $this->errorInternal('No query results for model [' . Contact::class . '] ' . $id); + } + return new Resource($contact); } diff --git a/app/Http/Controllers/Api/Common/Dashboards.php b/app/Http/Controllers/Api/Common/Dashboards.php index 30d7bdd1d..20bdf9ef3 100644 --- a/app/Http/Controllers/Api/Common/Dashboards.php +++ b/app/Http/Controllers/Api/Common/Dashboards.php @@ -39,6 +39,10 @@ class Dashboards extends ApiController try { $dashboard = Dashboard::with('widgets')->find($id); + if (! $dashboard instanceof Dashboard) { + return $this->errorInternal('No query results for model [' . Dashboard::class . '] ' . $id); + } + // Check if user can access dashboard $this->canAccess($dashboard); diff --git a/app/Http/Controllers/Api/Common/Items.php b/app/Http/Controllers/Api/Common/Items.php index bdfc80a76..09fd82974 100644 --- a/app/Http/Controllers/Api/Common/Items.php +++ b/app/Http/Controllers/Api/Common/Items.php @@ -34,6 +34,10 @@ class Items extends ApiController { $item = Item::with('category', 'taxes')->find($id); + if (! $item instanceof Item) { + return $this->errorInternal('No query results for model [' . Item::class . '] ' . $id); + } + return new Resource($item); } diff --git a/app/Http/Controllers/Api/Document/DocumentTransactions.php b/app/Http/Controllers/Api/Document/DocumentTransactions.php index d62351fec..16efc6f0e 100644 --- a/app/Http/Controllers/Api/Document/DocumentTransactions.php +++ b/app/Http/Controllers/Api/Document/DocumentTransactions.php @@ -48,6 +48,10 @@ class DocumentTransactions extends ApiController { $transaction = Transaction::documentId($document_id)->find($id); + if (! $transaction instanceof Transaction) { + return $this->errorInternal('No query results for model [' . Transaction::class . '] ' . $id); + } + return new Resource($transaction); } diff --git a/app/Http/Controllers/Api/Document/Documents.php b/app/Http/Controllers/Api/Document/Documents.php index 95c8a635c..568bc0ca7 100644 --- a/app/Http/Controllers/Api/Document/Documents.php +++ b/app/Http/Controllers/Api/Document/Documents.php @@ -39,6 +39,10 @@ class Documents extends ApiController $document = Document::where('document_number', $id)->first(); } + if (! $document instanceof Document) { + return $this->errorInternal('No query results for model [' . Document::class . '] ' . $id); + } + return new Resource($document); } diff --git a/app/Http/Controllers/Api/Settings/Currencies.php b/app/Http/Controllers/Api/Settings/Currencies.php index a646340df..8480eb91b 100644 --- a/app/Http/Controllers/Api/Settings/Currencies.php +++ b/app/Http/Controllers/Api/Settings/Currencies.php @@ -39,6 +39,10 @@ class Currencies extends ApiController $currency = Currency::where('code', $id)->first(); } + if (! $currency instanceof Currency) { + return $this->errorInternal('No query results for model [' . Currency::class . '] ' . $id); + } + return new Resource($currency); } diff --git a/app/Http/Controllers/Api/Settings/Settings.php b/app/Http/Controllers/Api/Settings/Settings.php index 33d091bfa..5ef7af136 100644 --- a/app/Http/Controllers/Api/Settings/Settings.php +++ b/app/Http/Controllers/Api/Settings/Settings.php @@ -47,6 +47,10 @@ class Settings extends ApiController $setting = Setting::where('key', $id)->first(); } + if (! $setting instanceof Setting) { + return $this->errorInternal('No query results for model [' . Setting::class . '] ' . $id); + } + return new Resource($setting); }