mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 02:41:05 +03:30
add rahyab notification service
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Exceptions\FieldNotExistsException;
|
||||
// use App\Scopes\OrderByIdScope;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait BasicModel
|
||||
{
|
||||
private int $pageSizeLimit = 48;
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
// if (! app()->runningInConsole()) {
|
||||
// static::addGlobalScope( new OrderByIdScope );
|
||||
// }
|
||||
}
|
||||
|
||||
public function getPerPage()
|
||||
{
|
||||
$pageSize = (int) request( 'per_page' , $this->perPage );
|
||||
return min( $pageSize , $this->pageSizeLimit );
|
||||
}
|
||||
|
||||
public function attributeExists( $attr ): bool
|
||||
{
|
||||
|
||||
return array_key_exists( $attr , $this->attributes );
|
||||
}
|
||||
|
||||
public function getField( $name )
|
||||
{
|
||||
$columnName = static::getColumn( $name );
|
||||
return $this->$columnName;
|
||||
}
|
||||
|
||||
public function setField( $name , $value ): void
|
||||
{
|
||||
$columnName = static::getColumn( $name );
|
||||
$this->$columnName = $value;
|
||||
}
|
||||
|
||||
public static function getColumnTable( $name ): string
|
||||
{
|
||||
return static::getTableName() . '.' . static::getColumn( $name );
|
||||
}
|
||||
|
||||
public static function getColumn( $name )
|
||||
{
|
||||
$fieldName = Arr::get( static::$maps , $name );
|
||||
|
||||
if ( is_null( $fieldName ) ) {
|
||||
throw new FieldNotExistsException( "field $name not exists" );
|
||||
}
|
||||
|
||||
return $fieldName;
|
||||
}
|
||||
|
||||
public function getTable()
|
||||
{
|
||||
return static::getTableName();
|
||||
}
|
||||
|
||||
public function fieldValue( $name )
|
||||
{
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function isLoaded( $relationName ): bool
|
||||
{
|
||||
return isset( $this->relations[ $relationName ] ) and $this->$relationName != null;
|
||||
}
|
||||
|
||||
abstract public static function getTableName();
|
||||
}
|
||||
Reference in New Issue
Block a user