devyousef/visitor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devyousef/visitor

最新稳定版本:v1.0.1

Composer 安装命令:

composer require devyousef/visitor

包简介

Provides an attribute to allow counting the number of visitors for multiple models within your Laravel app

README 文档

README

Provides an attribute to allow counting the number of visitors for multiple models within your Laravel app

Installation

You can install the package via composer:

composer require devyousef/visitor

You can publish the migrations with:

php artisan vendor:publish --provider="Devyousef\Visitor\Providers\VisitorServiceProvider" --tag="migrations"

After that run the migrations:

php artisan migrate

As with most Laravel packages, if you're using Laravel 5.5 or later, the package will be auto-discovered (learn more if this is new to you).

If you're using a version of Laravel before 5.5, you'll need to register the Rateable service provider. In your config/app.php add Devyousef\Visitor\Providers\VisitorServiceProvider to the end of the $providers array.

'providers' => [

    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    ...
    Devyousef\Visitor\Providers\VisitorServiceProvider::class,

],

Usage

In order to mark a model as "visitorable", import the Visitorable trait.

<?php

namespace App\Models;

use Devyousef\Visitor\Traits\Visitorable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Visitorable;
    //
}

Now, your model has access to a few additional methods.

Now to calculate the number of visitors when visiting a post, for example we use visit() . Note that the user must be added as a parameter:

$post = Post::first();
$user = Auth::user();
$post->visit($user);

Then to display the number of visitors we use visitorCount()

$postVisitor = Post::first()->visitorCount();
dd($postVisitor);

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-26