Skip to content

Commit

Permalink
Merge pull request #84 from nguyenanhung/v3.x
Browse files Browse the repository at this point in the history
Update Project at Tue Sep 26 12:59:01 +07 2023
  • Loading branch information
nguyenanhung authored Sep 26, 2023
2 parents d28babd + ea5ee4c commit 864f79e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
interface Environment
{
public const PROJECT_NAME = 'My Database Packages by HungNG';
public const VERSION = '3.1.4';
public const LAST_MODIFIED = '2023-08-13';
public const VERSION = '3.1.5';
public const LAST_MODIFIED = '2023-09-26';
public const AUTHOR_NAME = 'Hung Nguyen';
public const AUTHOR_EMAIL = '[email protected]';
public const AUTHOR_URL = 'https://nguyenanhung.com';
Expand Down
36 changes: 36 additions & 0 deletions src/Model/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,42 @@ public function getValue($wheres = '', $fields = 'id', $fieldOutput = '')
return $result;
}

/**
* Hàm lấy giá trị 1 field của bản ghi dựa trên điều kiện 1 bản ghi đầu vào
*
* Đây là hàm cơ bản, chỉ áp dụng check theo 1 field
*
* Lấy bản ghi đầu tiên phù hợp với điều kiện
*
* @param string|array $wheres Giá trị cần kiểm tra
* @param string|mixed $fields Field tương ứng với giá tri kiểm tra, ví dụ: ID
* @param string|mixed $fieldOutput field kết quả đầu ra
*
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|mixed|null|object
* @see https://laravel.com/docs/6.x/queries#selects
*
* @author: 713uk13m <[email protected]>
* @time : 10/16/18 11:51
*
*/
public function getValueOrEmpty($wheres = '', $fields = 'id', $fieldOutput = '')
{
$this->connection();
$db = DB::table($this->table);
$db = $this->prepareJoinStatement($db);
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $fields);
$this->logger->debug(__FUNCTION__, 'SQL Queries: ' . $query->toSql());
$result = $query->first();
// $this->logger->debug(__FUNCTION__, 'Result from DB => ' . json_encode($result));
if (!empty($fieldOutput) && ($result !== null) && isset($result->$fieldOutput)) {
return $result->$fieldOutput;
}

$this->logger->error(__FUNCTION__, 'Không tìm thấy cột dữ liệu ' . $fieldOutput);

return null;
}

/**
* Hàm lấy giá trị 1 field của bản ghi dựa trên điều kiện 1 bản ghi đầu vào - Đa điều kiện
*
Expand Down

0 comments on commit 864f79e

Please sign in to comment.