- Upgrading from v6.0.1 to v6.0.2
- Upgrading from v5.2.1 to v6.0.0
- Upgrading from v5.2.0 to v5.2.1
- Upgrading from v5.1.0 to v5.2.0
- Upgrading from v5.0.0 to v5.1.0
- Upgrading from v4.1.1 to v5.0.0
- Upgrading from v2.4.3 to v3.0.0
- Upgrading from v2.4.2 to v2.4.3
- Upgrading from v2.1.0 to v2.2.0
- Upgrading from v2.0.0 to v2.1.0
- Upgrading from v1.0.5 to v2.0.0
There are no manual changes needed.
There are no manual changes needed.
Make sure you're on a supported PHP version. These are ^7.4 or ^8.0.
If you have published the config file of this package, you will have to remove the cache.lifetime_in_minutes
key manually.
-/*
- * Default lifetime of cached views count in minutes.
- */
-'lifetime_in_minutes' => 60,
The parameters of the orderByViews
query scope in the Viewable
contract have been changed.
-public function scopeOrderByViews(Builder $query, string $direction = 'desc', $period = null): Builder;
+public function scopeOrderByViews(Builder $query, string $direction = 'desc', ?Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count'): Builder;
The parameters of the orderByViews
query scope in the Viewable
contract have been changed.
-public function scopeOrderByUniqueViews(Builder $query, string $direction = 'desc', $period = null): Builder;
+public function scopeOrderByUniqueViews(Builder $query, string $direction = 'desc', ?Period $period = null, ?string $collection = null, string $as = 'unique_views_count'): Builder;
The default cache lifetime functionality has been removed. The default value is now null
, which means it will be cached forever.
Look for all occurrences of the remember
method and pass the desired lifetime.
- The
$viewable
argument of theforViewable
method cannot benull
anymore. - The
record
method has nowbool
as return typehint. - The
destroy
method has nowvoid
as return typehint. - The
$period
argument of theperiod
method has now a typehint of?Period
. - The
$name
argument of theperiod
method has now a typehint of?string
. - The default value
null
of the$lifetime
argument of theremember
method has been removed.
- The
ip
method has now?string
as return typehint.
When the collection is not given, thus null, all views will be counted.
Let's say we have three views of which one has been stored in a collection called abc
.
Before: ->count()
will return 2
After: ->count()
will return 3
The record
method will now throw an ViewRecordException
exception when trying to record a view for a viewable type.
The following internal classes have changed. If you're extending or using them, check for any breaking changes.
CyrildeWit\EloquentViewable\CacheKey
CyrildeWit\EloquentViewable\CooldownManager
CyrildeWit\EloquentViewable\Views
CyrildeWit\EloquentViewable\Visitor
There are no manual changes needed.
There are no manual changes needed.
The following code is not valid anymore:
views()->count();
Use the View
Eloquent model.
First, you need to read the changelog and take a look at the comparison between your current used version and v5.0.0
, so you have a broad overview of what has changed.
This package now requires Laravel ^6.0
or ^7.0
.
The underlying queries that this package creates has been changed completely. For example, the order by query scopes no no longer uses a left join.
In the most basic use cases of this package, you will likely experience no issues at all, but it's still possible. Please check all your usages of the Views
class (views()
) manually for broken functionality.
The CyrildeWit\EloquentViewable\Viewable
trait has been renamed to CyrildeWit\EloquentViewable\InteractsWithViews
.
If you have published the config file of this package, you will have to rename the key of session
to cooldown
.
The current cooldown configuration is posted below:
/*
|--------------------------------------------------------------------------
| Cooldown Configuration
|--------------------------------------------------------------------------
*/
'cooldown' => [
/*
* Everthing will be stored under the following key in the session.
*/
'key' => 'cyrildewit.eloquent-viewable.cooldowns',
],
The type of the primary key id
has been changed to a big integer.
Create a new migration for your views table with the following contents:
$table->bigIncrements('id')->change();
The delayInSession
method of the Views
builder has been renamed to cooldown
.
Example:
views($post)->cooldown(now()->addMinutes(30))->record();
You can no longer override the ip address and visitor id using the overrideIpAddress
and overrideVisitor
method on the Views
builder.
You will have to create your own Visitor
class to provide custom values.
Take a look a the documentation on how to do this.
If you have created your own HeaderResolver
or IpAddressResolver
, refactor your code to adhere to the new Visitor
class implementation.
The logic from the VisitorCookieRepository
repository has been moved to the new Visitor
class. If you have used or overwritten this class, you will have to update your code.
Although, it's never documented you may have used the internal uniqueVisitor
scope of the View
eloquent model. This scope has been removed. If you rely on it, you will need to extend the View
class and add this method manually.
If you have used the internal ViewSessionHistory
you will have to update your code to use the new CooldownManager
.
This class was used internally
First, you need to read the changelog, so you have a broad overview of what has changed.
In Progress
Run the following migration to update the visitor
column.
$table->text('visitor')->change();
If you have published the config file of this package, you will have to copy the following snippet to your config file:
/*
|--------------------------------------------------------------------------
| Session Configuration
|--------------------------------------------------------------------------
*/
'session' => [
/*
* Everthing will be stored under the following key.
*/
'key' => 'cyrildewit.eloquent-viewable.session',
],
Take a look at the original file to find the right location.
There are no manual changes needed.
The package has been renamed from Laravel Page View Counter
to Eloquent Viewable
.
While v1.0.5
already required PHP 7.0 and higher, it is now added to the composer.json file.
The license has been changed from MIT
to Apache 2.0
.
You can install the new package via composer using:
composer require cyrildewit/eloquent-viewable
Replace CyrildeWit\PageViewCounter\PageViewCounterServiceProvider::class
with CyrildeWit\EloquentViewable\EloquentViewableServiceProvider::class
in providers.
If your app is in development, you can publish the new migration file with:
php artisan vendor:publish --provider="CyrildeWit\EloquentViewable\EloquentViewableServiceProvider" --tag="migrations"
Otherwise, you can use the update_views_table
migration to upgrade. It can be found at resources/database/.
First you have to publish the new config file with:
php artisan vendor:publish --provider="CyrildeWit\EloquentViewable\EloquentViewableServiceProvider" --tag="config"
Read this config file and update the fields if needed!
- Replace
use CyrildeWit\PageViewCounter\Traits\HasPageViewCounter;
withuse CyrildeWit\EloquentViewable\Viewable;
. - Replace
use HasPageViewCounter;
withuse Viewable;
.
For example:
use Illuminate\Database\Eloquent\Model;
use CyrildeWit\EloquentViewable\Viewable;
class Post extends Model
{
use Viewable;
// ...
}
- Find all usages of
addPageView()
and replace it withaddView()
.
Note: this feature has been made available again in v2.1.0
! See the README!
- Find all usages of
addPageViewThatExpiresAt(<DateTime>)
and replace it withaddView()
.
- Find all usages of
getPageViews()
and replace it withgetViews()
. - Find all usages of
getPageViewsFrom(<DateTime>)
and replace it withgetViews(Period::since(<DateTime>))
. - Find all usages of
getPageViewsBefore(<DateTime>)
and replace it withgetViews(Period::upto(<DateTime>))
. - Find all usages of
getPageViewsBetween(<DateTime>)
and replace it withgetViews(Period::create(<DateTime>, <DateTime>))
. - Find all usages of
getUniquePageViews()
and replace it withgetUniqueViews()
. - Find all usages of
getUniquePageViewsFrom(<DateTime>)
and replace it withgetUniqueViews(Period::since(<DateTime>))
. - Find all usages of
getUniquePageViewsBefore(<DateTime>)
and replace it withgetUniqueViews(Period::upto(<DateTime>))
. - Find all usages of
getUniquePageViewsBetween(<DateTime>)
and replace it withgetUniqueViews(Period::create(<DateTime>, <DateTime>))
.
The DateTransformers feature has been removed from v2.0.0.