prajwal89 / lara-click-insights
此包的最新版本(v0.1.0)没有可用的许可信息。
跟踪印象和点击
v0.1.0
2024-05-11 06:06 UTC
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/support: ^10.0|^11.0
This package is auto-updated.
Last update: 2024-09-11 07:12:10 UTC
README
使用 Lara Click Insights 记录任何模型的印象和点击
安装
- 通过 composer 安装包
composer require prajwal89/lara-click-insights
- 发布前端资源
php artisan vendor:publish --tag=lara-click-insights-assets
- 发布数据库迁移
php artisan vendor:publish --tag=lara-click-insights-migrations
- 发布数据库配置(可选)
php artisan vendor:publish --tag=lara-click-insights-config
或者,您可以使用以下命令发布以上所有内容
php artisan vendor:publish
提示时,选择 Prajwal89\LaraClickInsights\LaraClickInsightsProvider。
在您的 HTML <head>
标签中,添加以下指令和 meta 标签
<html> <head> <meta name="csrf-token" content="{{ csrf_token() }}"> ... @LaraClickInsightsJs </head>
别忘了运行 php artisan migrate
用法
您想要跟踪印象的 Eloquent 模型应该使用 Prajwal89\LaraClickInsights\Traits\ImpressionTrackable
特性。
namespace App; use Prajwal89\LaraClickInsights\Traits\ImpressionTrackable; use Illuminate\Database\Eloquent\Model; class YourEloquentModel extends Model { use ImpressionTrackable; ... }
该特性包含一个抽象方法 trackingAttribute()
,您必须在您的客户端自行实现。这应该看起来像这样
<!-- cards that you want to track --> @foreach($yourEloquentModels as $yourEloquentModel) <a href="/xyz" {!! $yourEloquentModel->trackingAttribute() !!}> <!-- card content --> </a> @foreach
这将添加用于识别可点击链接的数据属性,如 data-clickable="yourEloquentModels:23:default"
别忘了使用 {!! !!}
许可
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件