diff --git a/ERD-Laravel-Guardian.png b/ERD-Laravel-Guardian.png new file mode 100644 index 0000000..59f9157 Binary files /dev/null and b/ERD-Laravel-Guardian.png differ diff --git a/composer.json b/composer.json index 747fd37..06713f1 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,10 @@ "email": "dinhcuongngo@gmail.com" } ], + "require": { + "php": "^7.2.5|^8.0", + "cuongnd88/lara-query-kit": "^1.2" + }, "autoload": { "psr-4": { "Cuongnd88\\LaraGuardian\\": "src/" diff --git a/src/Guardian/Traits/QueryKit.php b/src/Guardian/Traits/QueryKit.php deleted file mode 100644 index c6bb69d..0000000 --- a/src/Guardian/Traits/QueryKit.php +++ /dev/null @@ -1,79 +0,0 @@ -getTable()} __INSERTKEYS__ VALUES __INSERTVALUE__ ON DUPLICATE KEY UPDATE __UPDATEVALUES__"; - $tmpInKeys = array_fill_keys($insertKeys, null); - $tmpUpKeys = array_fill_keys($updateKeys, null); - - try { - DB::beginTransaction(); - foreach ($data as $item) { - $insertValue = array_intersect_key($item, $tmpInKeys); - - $updateValue = implode(', ', array_map( - function ($v, $k) { return sprintf("`%s`='%s'", $k, $v); }, - array_intersect_key($item, $tmpUpKeys), - $updateKeys - )); - - $statement = str_replace( - ['__INSERTKEYS__', '__INSERTVALUE__', '__UPDATEVALUES__'], - ["(`" . implode("`,`", $insertKeys) . "`)", "('" . implode("','", $insertValue) . "')", $updateValue], - $query - ); - DB::statement($statement); - } - DB::commit(); - } catch (\Exception $e) { - DB::rollBack(); - report($e); - throw new \Exception($e->getMessage()); - } - } - - /** - * Get the array of columns - * - * @return mixed - */ - public function getTableColumns() { - return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable()); - } - - /** - * Retrieve a subset of the output data - * - * @param mixed $query - * @param array $columns - * - * @return mixed - */ - public function scopeExcept($query, array $columns = []) - { - $select = ['*']; - if ($columns && empty($this->except)) { - $select = array_diff($this->getTableColumns(), $columns); - } - if ($this->except && empty($columns)) { - $select = array_diff($this->getTableColumns(), $this->except); - } - return $query->select($select); - } -} diff --git a/src/Models/Action.php b/src/Models/Action.php index 2703a30..b767521 100644 --- a/src/Models/Action.php +++ b/src/Models/Action.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Guardian\Traits\QueryKit; +use App\Traits\QueryKit; class Action extends Model { diff --git a/src/Models/Group.php b/src/Models/Group.php index 321e656..08f991d 100644 --- a/src/Models/Group.php +++ b/src/Models/Group.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Guardian\Traits\QueryKit; +use App\Traits\QueryKit; class Group extends Model { diff --git a/src/Models/Page.php b/src/Models/Page.php index 764e77e..1a8bf7f 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Guardian\Traits\QueryKit; +use App\Traits\QueryKit; class Page extends Model {