From 886ca7f1e060d66e04d1624a9c01134e90ecfcc5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Jan 2023 19:56:13 +1100 Subject: [PATCH] Fixes for staticmodel scopes --- .../Requests/Activity/ShowActivityRequest.php | 4 ++-- app/Models/Activity.php | 14 ----------- app/Models/ClientGatewayToken.php | 14 +---------- app/Models/CompanyGateway.php | 8 ------- app/Models/Currency.php | 1 - app/Models/GroupSetting.php | 24 +++++++++++++++++-- app/Models/Payment.php | 8 ------- app/Models/StaticModel.php | 3 +-- 8 files changed, 26 insertions(+), 50 deletions(-) diff --git a/app/Http/Requests/Activity/ShowActivityRequest.php b/app/Http/Requests/Activity/ShowActivityRequest.php index 24dec84689b5..d7c745cb5d10 100644 --- a/app/Http/Requests/Activity/ShowActivityRequest.php +++ b/app/Http/Requests/Activity/ShowActivityRequest.php @@ -23,7 +23,7 @@ class ShowActivityRequest extends Request */ public function authorize() : bool { - return auth()->user()->isAdmin(); - // return auth()->user()->can('view', Activity::class); + // return auth()->user()->isAdmin(); + return auth()->user()->can('view', Activity::class); } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 442621808921..5c2af53d3ab9 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -375,18 +375,4 @@ class Activity extends StaticModel return $this->belongsTo(Company::class); } -// /** -// * @return mixed -// */ -// public function resolveRouteBinding($value, $field = null) -// { -// if (is_numeric($value)) { -// throw new ModelNotFoundException("Record with value {$value} not found"); -// } - -// return $this -// //->withTrashed() -// ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); -// } - } \ No newline at end of file diff --git a/app/Models/ClientGatewayToken.php b/app/Models/ClientGatewayToken.php index 50f616398195..5efcea44ad83 100644 --- a/app/Models/ClientGatewayToken.php +++ b/app/Models/ClientGatewayToken.php @@ -69,17 +69,5 @@ class ClientGatewayToken extends BaseModel { return $this->belongsTo(User::class)->withTrashed(); } - - // /** - // * Retrieve the model for a bound value. - // * - // * @param mixed $value - // * @param null $field - // * @return Model|null - // */ - // public function resolveRouteBinding($value, $field = null) - // { - // return $this - // ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); - // } + } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index b5c26fd6975b..a31dc174602d 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -412,12 +412,4 @@ class CompanyGateway extends BaseModel return route('payment_webhook', ['company_key' => $this->company->company_key, 'company_gateway_id' => $this->hashed_id]); } - // public function resolveRouteBinding($value, $field = null) - // { - - // return $this - // ->where('id', $this->decodePrimaryKey($value))->withTrashed()->firstOrFail(); - // } - - } diff --git a/app/Models/Currency.php b/app/Models/Currency.php index 6a1ae1d5c15f..2da76e6541e0 100644 --- a/app/Models/Currency.php +++ b/app/Models/Currency.php @@ -23,7 +23,6 @@ class Currency extends StaticModel 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', - //'precision' => 'string', 'precision' => 'integer', ]; } diff --git a/app/Models/GroupSetting.php b/app/Models/GroupSetting.php index 539dc9b8fd32..b465c8a03039 100644 --- a/app/Models/GroupSetting.php +++ b/app/Models/GroupSetting.php @@ -14,14 +14,13 @@ namespace App\Models; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException; class GroupSetting extends StaticModel { use MakesHash; use SoftDeletes; - //public $timestamps = false; - protected $casts = [ 'settings' => 'object', 'updated_at' => 'timestamp', @@ -65,4 +64,25 @@ class GroupSetting extends StaticModel return $this->morphMany(Document::class, 'documentable'); } + /** + * Retrieve the model for a bound value. + * + * @param mixed $value + * @param null $field + * @return Model|null + */ + public function resolveRouteBinding($value, $field = null) + { + + if (is_numeric($value)) { + throw new ModelNotFoundException("Record with value {$value} not found"); + } + + return $this + ->withTrashed() + ->company() + ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + + } } + diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 12c90bbecfd8..32a3e2cf3101 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -292,14 +292,6 @@ class Payment extends BaseModel return new PaymentService($this); } - - // public function resolveRouteBinding($value, $field = null) - // { - // return $this - // ->withTrashed() - // ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); - // } - public function refund(array $data) :self { return $this->service()->refundPayment($data); diff --git a/app/Models/StaticModel.php b/app/Models/StaticModel.php index f20b97ff147a..5f5b9df0bd13 100644 --- a/app/Models/StaticModel.php +++ b/app/Models/StaticModel.php @@ -57,8 +57,7 @@ class StaticModel extends Model } return $this - ->withTrashed() - ->company() ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + } }