fix : Trait 추가 및 query 디버깅 소스 수정
This commit is contained in:
@@ -77,9 +77,10 @@ public static function validate(
|
||||
return $condition ? null : self::error($message, $code, $extra);
|
||||
}
|
||||
|
||||
public static function response($type = '', $query = '', $debug = false, $key = ''): array
|
||||
public static function response($type = '', $query = '', $key = ''): array
|
||||
{
|
||||
if ($debug && $type != 'success') DB::enableQueryLog(); // 쿼리 추적
|
||||
if (app()->environment('local')) $debug = true;
|
||||
if ($debug) DB::enableQueryLog(); // 쿼리 추적
|
||||
|
||||
$result = match ($type) {
|
||||
'get' => $key ? $query->get()->keyBy($key) : $query->get(),
|
||||
|
||||
@@ -48,8 +48,16 @@ public function handle(Request $request, Closure $next)
|
||||
$user = $accessToken->tokenable;
|
||||
|
||||
if ($user) {
|
||||
$request->attributes->set('tenant_id', $user->tn_num);
|
||||
$request->attributes->set('api_user', $user->mb_num);
|
||||
// 기본 테넌트(여러개 소속시 우선순위)
|
||||
$tenantId = $user->tenant?->tenant_id ?? $user->userTenants->first()?->tenant_id;
|
||||
|
||||
$request->attributes->set('tenant_id', $tenantId);
|
||||
$request->attributes->set('api_user', $user->id);
|
||||
|
||||
|
||||
// ApiKeyMiddleware 등에서
|
||||
app()->instance('api_user', $user->id);
|
||||
app()->instance('tenant_id', $tenantId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class Tenant extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes, ModelTrait;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -20,5 +21,14 @@ public function register(): void
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
Builder::macro('debug', function($debug = null) {
|
||||
if (is_null($debug) && app()->environment('local')) {
|
||||
$debug = true;
|
||||
}
|
||||
if ($debug) {
|
||||
\DB::enableQueryLog();
|
||||
}
|
||||
return $this;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ class ProductService
|
||||
/**
|
||||
* 회원 조회(리스트)
|
||||
*/
|
||||
public static function getCategory(string $userToken, bool $debug = false)
|
||||
public static function getCategory()
|
||||
{
|
||||
$query = CommonCode::where('code_group','category')->where('parent_id',null);
|
||||
|
||||
return ApiResponse::response('get', $query, true);
|
||||
return ApiResponse::response('get', $query);
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
app/Traits/ModelTrait.php
Normal file
24
app/Traits/ModelTrait.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
trait ModelTrait
|
||||
{
|
||||
/**
|
||||
* 날짜 직렬화 포맷 오버라이드 (모델에 추가해서 사용)
|
||||
*/
|
||||
protected function serializeDate(DateTimeInterface $date)
|
||||
{
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Active 상태 조회
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user