Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Viewable Laravel Package

cyrildewit/eloquent-viewable

Eloquent Viewable is a minimalistic analytics package for Laravel that adds seamless view tracking to Eloquent models, with cooldowns, queued recording, unique counts, and period-based queries.

View on GitHub
Deep Wiki
Context7
v8.0.1

Changed

  • Visitor now receives the cookie jar through its constructor (Illuminate\Contracts\Cookie\QueueingFactory) and reads the existing visitor cookie from the injected request, instead of going through the Cookie facade (breaking only for subclasses that override the constructor)
  • The views() helper now throws an InvalidArgumentException when given a class name that does not implement Contracts\Viewable, instead of a TypeError from deeper inside the package

Fixed

  • Fixed soft deletes removing the views of a viewable model; ViewableObserver now skips soft deletes and only destroys views on a force delete, so a restored model keeps its view count. If you relied on a soft delete purging views, call views($model)->destroy() yourself
  • Fixed expired cooldowns wiping every cooldown for the same viewable type; CooldownManager built the session key to forget from an empty array_column() result, so it removed the whole namespace instead of the one expired entry
  • Fixed Visitor::hasDoNotTrackHeader() always returning false; it looked the header up as HTTP_DNT, which is the $_SERVER key, while Laravel's header bag exposes it as DNT (the Visitor::DNT constant now holds 'DNT')
  • Fixed orderByUniqueViews() and withViewsCount(unique: true) ordering and counting by total views instead of distinct visitors; Laravel drops the extra select added inside a withCount constraint, so the distinct count is now passed as the aggregate expression
v8.0.0

See the upgrade guide for detailed migration instructions.

Added

  • Added native type declarations across the public API

Changed

  • Raised the minimum PHP version to ^8.5
  • The Views contract now declares the existing useVisitor() method (breaking only for classes that implement Contracts\Views directly)
  • Changed the cooldown() and remember() parameters on the Views contract to be typed DateTimeInterface|int|null
  • Changed the scopeWithinPeriod() method on the View contract to declare a void return type
  • Narrowed Period::getStartDateTime()/getEndDateTime() to return ?CarbonInterface
  • Marked the InvalidPeriod and ViewRecordException exceptions as final (breaking only for code that extends them)
  • The Viewable contract now uses [@mixin](https://github.com/mixin) \Illuminate\Database\Eloquent\Model instead of redeclaring the getKey() and getMorphClass() methods
  • The View contract now uses [@mixin](https://github.com/mixin) \Illuminate\Database\Eloquent\Model and declares the existing scopeCollection() method (breaking only for classes that implement Contracts\View directly)
  • Modernized the create_views_table migration stub (typed properties and return types)
  • Changed the visitor column in the create_views_table migration stub from text to string (VARCHAR(255)) so it can be indexed directly (only affects newly published migrations)
  • Changed the default config models.view.connection and cache.store to null, so they now defer to the application's default database connection and cache store instead of reading env('DB_CONNECTION') and the deprecated env('CACHE_DRIVER') (only affects newly published config)
  • Migrated the test suite from PHPUnit to Pest (development only; no impact on consumers)
  • Redesigned Period as a final, immutable (readonly) value object; relative periods are now built with the new Support\PeriodInterval and Support\PeriodAnchor enums, and date parsing defers to Carbon::make() (the factory methods, getStartDateTime()/getEndDateTime(), and the cache-key format are unchanged)

Removed

  • Dropped support for Laravel 6 through 12 (illuminate/* now requires ^13.0)
  • Dropped support for Carbon 2 (nesbot/carbon now requires ^3.0)
  • Removed the getStartDateTimeString(), getEndDateTimeString(), getStartDateTimestamp() and getEndDateTimestamp() getters from Period
  • Removed the Period::PAST_* and Period::SUB_* constants and the sub(), subToday() and subNow() static helpers
  • Removed the Period::getSubType(), getSubValue(), hasFixedDateTimes(), setStartDateTime(), setEndDateTime(), setFixedDateTimes(), setSubType() and setSubValue() methods (Period is now immutable)
v7.1.1

What's Changed

Fixed

  • Fixed cooldown pruning when the session uses JSON serialization, where expires_at is restored as a string instead of a Carbon instance (#326)

New Contributors

Full Changelog: https://github.com/cyrildewit/eloquent-viewable/compare/v7.1.0...v7.1.1

v7.1.0

Changed

  • Add support for Laravel 13
v7.0.6

What's Changed

New Contributors

Full Changelog: https://github.com/cyrildewit/eloquent-viewable/compare/v7.0.5...v7.0.6

v7.0.5

What's Changed

New Contributors

Full Changelog: https://github.com/cyrildewit/eloquent-viewable/compare/v7.0.4...v7.0.5

v6.1.0

Changed

v6.0.2

Fixed

  • Revert breaking change of remember method in Views contract. The $lifetime variable has now a default value of null.
v6.0.1

Fixed

  • Revert breaking change of remember method in Views class. The $lifetime variable has now a default value of null.
v6.0.0

Added

  • Added bool return typehint to record method in Views contract.
  • Added void return typehint to destroy method in Views contract.
  • The ViewRecordException will be thrown when trying to record a view for a viewable type.
  • The ViewRecorded event will be fired when a new view is recorded.
  • Added Views typehint to global views() function.
  • Added bool return typehint to isCrawler method in CrawlerDetector contract.

Changed

  • Set required PHP versions in composer.json to ^7.4|^8.0.
  • The creating of the View instance has been moved into its own method protected function createView(): View.
  • The $viewable argument of the forViewable method in Views contract cannot be nullable anymore.
  • Changed the method arguments of orderByViews and orderByUniqueViews query scope in Viewable contract and InteractsWithViews trait.
  • Changed the method arguments of withViewsCount query scope in InteractsWithViews trait.
  • Added nullable Period class typehint to $period argument of period method in Views contract.
  • Made $name argument nullable in Views contract.
  • Changed return typehint of ip method in Visitor contract to ?string.
  • Change DateTime typehint to DateTimeInterface in InvalidPeriod exception.

Removed

  • Removed lifetime_in_minutes option from config file.

Fixed

  • Fixed count method of Views class to count all views, including the collections (#241).
v6.0.0-alpha.1
v5.2.1

Changed

  • Add support for Laravel 8
v5.2.0

Fixed

  • Use CyrildeWit\EloquentViewable\Contracts\Views to resolve Views instance from container.
v5.1.0

Changed

  • Remove default value (null) for viewable in views() helper.
v5.0.0

Added

  • Added Views contract.
  • Added Visitor contract.
  • Added the Visitor class which represents the current visitor.
  • Added protected getViewableTypeSlug() to CacheKey::class.
  • Added orderByViews query scope to Viewable trait.
  • Added orderByUniqueViews query scope to Viewable trait.
  • Added withViewsCount query scope to Viewable trait.

Changed

  • The CyrildeWit\EloquentViewable\Viewable trait has been renamed to CyrildeWit\EloquentViewable\InteractsWithViews.
  • Renamed session.key to cooldown.key in configuration file.
  • Changed the Views class constructor arguments. Added the Visitor as first argument and removed VisitorCookieRepository $visitorCookieRepository, rawlerDetector $crawlerDetector and IpAddressResolver $ipAddressResolver.
  • Replaced calls to $this->crawlerDetector in Views with new Visitor class implementation.
  • Replaced calls to requestHasDoNotTrackHeader in Views with new Visitor class implementation.
  • Changed type of primary key from increments to bigIncrements in views table migration.
  • Bumped minimum requirements for Laravel framework components to ^6.0|^7.0.
  • Removed check for provided viewable type in getConnectionName(), getDatabaseName(), getModelSlug() and getKeySlug in CacheKey::class.
  • Renamed ViewSessionHistory class to CooldownMananger.
  • Changed constructor of CooldownManager class. The Illuminate\Contracts\Config\Repository has been added as first parameter and the cooldown key is now retrieved from this instance.
  • The Views class now implements the Views contract.
  • The constructor of the Views class has been changed.
  • Moved Facades/Views to src/ and renamed it to ViewsFacade.
  • The global views() helper now supports viewable types.

Removed

  • Dropped support for nesbot/carbon ^1.22.
  • Removed the deprecated overrideIpAddress method from the Views class.
  • Removed the deprecated overrideVisitor method from the Views class.
  • Removed requestHasDoNotTrackHeader method from Views class.
  • Removed $viewableType argument from constructor of CacheKey::class.
  • Removed static fromViewableType method from CacheKey::class.
  • Removed HeaderResolver contract and class.
  • Removed IpAddressResolver contract and class.
  • Removed uniqueVisitor() scope from View model.
  • Removed Enums\SortDirection class.
  • Removed OrderByViewsScope class.
  • Removed the countByType method from the Views class.
  • Removed the VisitorCookieRepository (logic is move to the Visitor class).
v5.0.0-alpha.2
v5.0.0-alpha.1
v5.0.0-alpha.0
v4.1.1

Fixed

  • Update required dependencies in composer.json to adhere to new Laravel 6 verison scheme
v4.1.0

Changed

  • Add support for Laravel 6
v4.0.0

Added

  • Added SortDirection enum class that contains a DESCENDING and ASCENDING constant
  • Added OrderByViewsScope class that can order a query by views based on some options
  • Added collection($collection) query scope to View model
  • Added the ability to pass a collection to the orderByViews and orderByUniqueViews query scope
  • Added a new CacheKey class with a new improved approach to making keys for the cache
  • Added getStartDateTimestamp and getEndDateTimestamp methods to the Period class for internal use
  • Added string $collection = null argument to push, createNamespaceKey and createViewableKey methods in ViewSessionHistory

Deprecated

  • Deprecated the overrideIpAddress method of the Views class. Please use the new useIpAddress(string $address) method instead.
  • Deprecated the overrideVisitor method of the Views class. Please use the new useVisitor(string $visitor) method instead.

Changed

  • Replaced inner code of the orderByViews and orderByUniqueViews query scope with the new OrderByViewsScope class
  • Removed the string type declaration from the getTable method in the View model class #165

Removed

  • Removed the Support\Key class with its references
v3.2.0

Added

  • Add support for Laravel 5.8

Changed

  • Use String and Array classes instead of the helper functions
v3.1.0

Fixed

  • Fixed the ability to pass an integer to the delayInSession method without getting an error
  • Type cast the cached views count otherwise PHP's type hint will fail

Added

  • Added the ability to override the visitor's unique ID that's used to distinguish unique views
  • Added the ability to specify a cache store that should be used by this package
v3.0.2

Fixed

  • The method delayInSession isn't working properly
v3.0.1

Fixed

  • Publishing package migrations results in error (#133)
v3.0.0

Added

  • Added Views class with facade
  • Added IpAddressResolver contract with implementation
  • Added HeaderResolver contract with implementation
  • Added VisitorCookieRepository class
  • Added global helper views
  • Added collection column to views table shema
  • Added withinPeriod scope to View model
  • Added uniqueVisitor scope to View model

Changed

  • Bumped minimum required PHP version to ^7.1
  • Require viewable models to implement the Viewable contract
  • Added global views() helper
  • Remove IP address as fallback for visitor cookie when it doesn't exists
  • Changed the isBot method name to isCrawler in CrawlerDetector contract and updated the CrawlerDetectAdapter
  • Changed the visibility of the $detector property from protected to private
  • Add support for 5.7.* of illuminate/config to composer.json
  • Moved config file from publishable/config to config/
  • Replace create_views_table stub with real migration file and load it inside the service provider
  • Allow strings to be passed to the constructor of the Period class
  • Extracted key generation logic from Period class to the Key class

Removed

  • Removed the ViewTracker class
  • Removed the ViewableService class
  • Removed the ProcessView job
  • Removed the update_views_table migration file from resources/database/migrations
  • Removed illuminate/bus as dependency
  • Removed illuminate/queue as dependency
  • Removed illuminate/routing as dependency
v2.5.0

Fixed

  • orderByViewsCount scope doesn't adhere to connection prefix
v2.4.3

Fixed

  • Data too long for column visitor
v2.4.2

Fixed

  • ProcessView job is always failing
v2.4.1

Fixed

  • View is saved before ProcessViews job is ran
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
labyrinthe/connect-php
encore2/laravel-admin2
cboxdk/laravel-console-kit
shapecode/doctrine-dbal-datetimeutc
gilads-otiannoh254/inertia-protocol
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
adachsoft/cli-process-tester
adachsoft/changelog-linter
adachsoft/collection
adachsoft/php-code-style
adachsoft/api-version-bundle