How to extend a Laravel vendor package
<p>I am trying to extend <a href="https://github.com/Kryptonit3/Counter" rel="nofollow noreferrer">Kryptonit3/Counter</a>. Particularly, I need to overwrite one private function inside the class Counter.php to retrieve only hits for the last 24 hours. </p>

<p>Counter.php private function:</p>

<pre><code>private static function countHits($page)
{
    $page_record = self::createPageIfNotPresent($page);
    return number_format($page_record-&gt;visitors-&gt;count());
}
</code></pre>

<p>The function I need:</p>

<pre><code>private static function countHits($page)
{
    $page_record = self::createPageIfNotPresent($page);
    return number_format($page_record-&gt;visitors()-&gt;where('created_at', '&gt;=', Carbon::now()-&gt;subDay())-&gt;count());
}
</code></pre>

<p>Therefore, I am looking for the right way to overwrite this package. </p>

<p><strong>Approach 1</strong>: Should I create my own class extending Counter.php and including my custom function in this class? If so, what happens with the private classes included in the original class? Should I create a service provider? How this service provider would look like?</p>

<p><strong>Approach 2</strong>: Should I fork the vendor package and update this package to my own need?</p>

<p>I already looked at all stackoverflow questions related to this topic but they are not clear enough.</p>

<p><strong>UPDATE:</strong>
This is what I did so far:</p>

<p>Create MyCounter class:</p>

<pre><code>&lt;?php

namespace App\Helpers\Counter;

use Kryptonit3\Counter\Counter;
class MyCounter extends Counter
{

}
</code></pre>

<p>Create MyCounterServiceProvider:</p>

<pre><code>&lt;?php

namespace App\Providers;

use App\Helpers\MyCounter;
use Illuminate\Support\ServiceProvider;

class MyCounterServiceProvider extends ServiceProvider
{
/**
 * Bootstrap the application services.
 *
 * @return void
 */
public function boot()
{
    //
}

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    $this-&gt;app['counter'] = $this-&gt;app-&gt;share(function($app)
    {
        $visitor = $app['visitor'];
        return new MyCounter($visitor);
    });
}
}
</code></pre>

<p>Create MyCounterFacade:</p>

<pre><code>&lt;?php

namespace App\Helpers\Counter;


use Illuminate\Support\Facades\Facade;

class MyCounterFacade extends Facade
{
    protected static function getFacadeAccessor() { return 'mycounter'; }
}
</code></pre>

<p>Include the provider and the alias inside config/app.php:</p>

<pre><code>App\Providers\MyCounterServiceProvider::class,
</code></pre>

<p>and</p>

<pre><code>'MyCounter'             =&gt; App\Helpers\Counter\MyCounterFacade::class,
</code></pre>