Fixes for staticmodel scopes

This commit is contained in:
David Bomba 2023-01-29 19:56:13 +11:00
parent e210d9f1bb
commit 886ca7f1e0
8 changed files with 26 additions and 50 deletions

View File

@ -23,7 +23,7 @@ class ShowActivityRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->isAdmin(); // return auth()->user()->isAdmin();
// return auth()->user()->can('view', Activity::class); return auth()->user()->can('view', Activity::class);
} }
} }

View File

@ -375,18 +375,4 @@ class Activity extends StaticModel
return $this->belongsTo(Company::class); 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();
// }
} }

View File

@ -69,17 +69,5 @@ class ClientGatewayToken extends BaseModel
{ {
return $this->belongsTo(User::class)->withTrashed(); 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();
// }
} }

View File

@ -412,12 +412,4 @@ class CompanyGateway extends BaseModel
return route('payment_webhook', ['company_key' => $this->company->company_key, 'company_gateway_id' => $this->hashed_id]); 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();
// }
} }

View File

@ -23,7 +23,6 @@ class Currency extends StaticModel
'updated_at' => 'timestamp', 'updated_at' => 'timestamp',
'created_at' => 'timestamp', 'created_at' => 'timestamp',
'deleted_at' => 'timestamp', 'deleted_at' => 'timestamp',
//'precision' => 'string',
'precision' => 'integer', 'precision' => 'integer',
]; ];
} }

View File

@ -14,14 +14,13 @@ namespace App\Models;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
class GroupSetting extends StaticModel class GroupSetting extends StaticModel
{ {
use MakesHash; use MakesHash;
use SoftDeletes; use SoftDeletes;
//public $timestamps = false;
protected $casts = [ protected $casts = [
'settings' => 'object', 'settings' => 'object',
'updated_at' => 'timestamp', 'updated_at' => 'timestamp',
@ -65,4 +64,25 @@ class GroupSetting extends StaticModel
return $this->morphMany(Document::class, 'documentable'); 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();
}
} }

View File

@ -292,14 +292,6 @@ class Payment extends BaseModel
return new PaymentService($this); 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 public function refund(array $data) :self
{ {
return $this->service()->refundPayment($data); return $this->service()->refundPayment($data);

View File

@ -57,8 +57,7 @@ class StaticModel extends Model
} }
return $this return $this
->withTrashed()
->company()
->where('id', $this->decodePrimaryKey($value))->firstOrFail(); ->where('id', $this->decodePrimaryKey($value))->firstOrFail();
} }
} }