Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Your website will need a dedicated "Cookie Policy" page containing extensive inf
<tr>
<td>{{ $cookie->name }}</td>
<td>{{ $cookie->description }}</td>
<td>{{ \Carbon\CarbonInterval::minutes($cookie->duration)->cascade() }}</td>
<td>{{ $cookie->getDurationForHumans() }}</td>
</tr>
@endforeach
</tbody>
Expand All @@ -453,16 +453,6 @@ Your website will need a dedicated "Cookie Policy" page containing extensive inf
<p>...</p>
```

A side note on `Carbon\CarbonInterval`'s `cascade` method: when working with years, some unexpected results could appear. By default, the `CarbonInterval` "year" factor will return 336 days instead of 365. It is possible to change this by defining your own factors (for instance in `App\Providers\AppServiceProvider`):

```php
$factors = \Carbon\CarbonInterval::getCascadeFactors();
$factors['years'] = [365, 'dayz'];
\Carbon\CarbonInterval::setCascadeFactors($factors);
```

More information on CarbonInterval's gotchas in [Constantin's blog post on chasingcode.dev](https://chasingcode.dev/blog/carbon-php-practical-examples/).

### Let your users change their mind

Users should be able to change their consent settings at any time. No worries, with this package it is quite simple to achieve: generate a button that will reset the user's cookies and show the consent modal again.
Expand Down
2 changes: 1 addition & 1 deletion resources/views/cookies.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@foreach($category->getCookies() as $cookie)
<li class="cookies__cookie">
<p class="cookies__name">{{ $cookie->name }}</p>
<p class="cookies__duration">{{ \Carbon\CarbonInterval::minutes($cookie->duration)->cascade() }}</p>
<p class="cookies__duration">{{ $cookie->getDurationForHumans() }}</p>
@if($cookie->description)
<p class="cookies__description">{{ $cookie->description }}</p>
@endif
Expand Down
7 changes: 7 additions & 0 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Whitecube\LaravelCookieConsent;

use Carbon\Carbon;

class Cookie
{
use Concerns\HasAttributes;
Expand Down Expand Up @@ -46,4 +48,9 @@ public function __call(string $method, array $arguments): static

return $this;
}

public function getDurationForHumans() : string
{
return Carbon::now()->diffForHumans(Carbon::now()->addMinutes($this->duration), true);
}
}