Laravel Page View Counter 文章浏览统计

Laravel Page View Counter 文章浏览统计

  1. 简单粗暴添加文章阅读统计

  2. 精细化添加文章阅读统计统计

  3. Package 改造添加文章阅读统计

1. 简单粗暴添加文章阅读统计

  1. Post 添加统计字段

    • php artisan make:migration add_post_counter_to_post_table --table=post

  2. Controller 添加增加

    • DB::table('post')->where('id', '=', $id)->increment('post_counter');

2.精细化添加文章阅读统计统计

3. Package 改造添加文章阅读统计

  1. Visitor.php

    1. Countable(interface)

    2. Weboap\Visitor\Services\Cache\CacheInterface

    3. Weboap\Visitor\Services\Geo\GeoInterface

    4. Weboap\Visitor\Storage\VisitorInterface

  2. VisitorInterface

    1. create

    2. get

    3. update

    4. delete

    5. all

    6. count

    7. clicksSum

    8. range

    9. increment

    10. QbVisitorRepository implements VisitorInterface

        1. $tableName $config $config
        2. __construct(Config $config, DB $db)
        3. setTable($table)
        4. getTable()
        5. create(array $data)
        6. get($ip)
        7. update($ip, array $data)
        8. delete($ip)
        9. all()
        10. increment($ip)
            * $this->db->table($this->getTable())->whereIp($ip)->increment('clicks');
        11. clicksSum()
        12. range($start, $end)
        13. clear()
  3. CacheInterface.php

    1. use Illuminate\Cache\CacheManager as Cache;

    2. __construct(Cache $cache)

    3. destroy($key)

    4. rememberForever($key, $data)

  4. GeoInterface

    1. use GeoIp2\Database\Reader;

    2. use GeoIp2\Exception\AddressNotFoundException;

    3. use Illuminate\Config\Repository as Config;

    4. use Weboap\Visitor\Ip;

    5. locate()

  5. ValidationInterface

    1. validate($ip)

  6. Visitor.php

    1. get($ip = null)

    2. log()

    3. forget($ip)

    4. has($ip)

    5. count($ip = null)

    6. all($collection = false)

4. Reference

  1. [Implementing A Page View Counter In Laravel]()

  2. Laravel 文章浏览数统计 (VisitorRegistry)

  3. Register your visitors, Page hits, and count for Laravel

标签: none

添加新评论