There are no manual changes needed.
There are no manual changes needed.
There are no manual changes needed, since there are no breaking changes.
There are no manual changes needed.
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,
orderByViews query scopeThe 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;
orderByUniqueViews query scopeThe 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.
Views contract$viewable argument of the forViewable method cannot be null anymore.record method has now bool as return typehint.destroy method has now void as return typehint.$period argument of the period method has now a typehint of ?Period.$name argument of the period method has now a typehint of ?string.null of the $lifetime argument of the remember method has been removed.Visitor contractip method has now ?string as return typehint.count method has been changedWhen 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\CacheKeyCyrildeWit\EloquentViewable\CooldownManagerCyrildeWit\EloquentViewable\ViewsCyrildeWit\EloquentViewable\VisitorThere 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',
],
views database tableThe 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();
overrideIpAddress and overrideVisitor usagesYou 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.
IpAddressResolverIf you have created your own HeaderResolver or IpAddressResolver, refactor your code to adhere to the new Visitor class implementation.
VisitorCookieRepositoryThe 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.
uniqueVisitor scope on View modelAlthough, 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.
ViewSessionHistoryIf you have used the internal ViewSessionHistory you will have to update your code to use the new CooldownManager.
OrderByViewsScope classThis 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
config/app.phpReplace 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!
use CyrildeWit\PageViewCounter\Traits\HasPageViewCounter; with use CyrildeWit\EloquentViewable\Viewable;.use HasPageViewCounter; with use Viewable;.For example:
use Illuminate\Database\Eloquent\Model;
use CyrildeWit\EloquentViewable\Viewable;
class Post extends Model
{
use Viewable;
// ...
}
->addPageView() to ->addView()addPageView() and replace it with addView().->addPageViewThatExpiresAt() to ->addView()Note: this feature has been made available again in v2.1.0! See the README!
addPageViewThatExpiresAt(<DateTime>) and replace it with addView().->getPageViews<suffix>() to ->getViews()getPageViews() and replace it with getViews().getPageViewsFrom(<DateTime>)and replace it with getViews(Period::since(<DateTime>)).getPageViewsBefore(<DateTime>)and replace it with getViews(Period::upto(<DateTime>)).getPageViewsBetween(<DateTime>)and replace it with getViews(Period::create(<DateTime>, <DateTime>)).getUniquePageViews() and replace it with getUniqueViews().getUniquePageViewsFrom(<DateTime>)and replace it with getUniqueViews(Period::since(<DateTime>)).getUniquePageViewsBefore(<DateTime>)and replace it with getUniqueViews(Period::upto(<DateTime>)).getUniquePageViewsBetween(<DateTime>)and replace it with getUniqueViews(Period::create(<DateTime>, <DateTime>)).The DateTransformers feature has been removed from v2.0.0.