diff --git a/src/Models/ShortUrlTracing.php b/src/Models/ShortUrlTracing.php index ebf7b19..c1c8017 100644 --- a/src/Models/ShortUrlTracing.php +++ b/src/Models/ShortUrlTracing.php @@ -14,7 +14,7 @@ class ShortUrlTracing extends Model /** * @var bool */ - public $incrementing = true; + public $incrementing = false; /** * @var string @@ -24,7 +24,7 @@ class ShortUrlTracing extends Model /** * @var string */ - protected $primaryKey = 'id'; + protected $primaryKey = 'short_url_id'; /** * @var string[] diff --git a/src/Repositories/UrlRepository.php b/src/Repositories/UrlRepository.php index 5d31568..2f1c4f0 100644 --- a/src/Repositories/UrlRepository.php +++ b/src/Repositories/UrlRepository.php @@ -56,14 +56,16 @@ public static function findOwnershipUrls(string $owner_type, int $owner_id): Col public static function getOwnershipUrlsCount(string $owner_type, int $owner_id): int { try { - return ShortUrl::whereIn('id', function ($query) use ($owner_type, $owner_id) { - $query->from('short_url_ownerships'); - $query->where([ - 'ownerable_type' => $owner_type, - 'ownerable_id' => $owner_id, - ]); - $query->select('short_url_id'); - })->count(); + return ShortUrl::query() + ->whereIn('id', function ($query) use ($owner_type, $owner_id) { + $query->from('short_url_ownerships'); + $query->where([ + 'ownerable_type' => $owner_type, + 'ownerable_id' => $owner_id, + ]); + $query->select('short_url_id'); + }) + ->count(); } catch (Exception $exception) { throw new UrlRepositoryException($exception->getMessage()); } @@ -94,7 +96,7 @@ public static function findByPlainText(string $plain_text): ShortUrl { try { return ShortUrl::where( - 'plain_text', 'like', $plain_text.'%' + 'plain_text', 'like', $plain_text . '%' )->with(self::defaultWithRelationship())->firstOrFail(); } catch (Exception $exception) { throw new UrlRepositoryException($exception->getMessage());