prajwal89/laravel-share-to

轻松生成和渲染社交分享按钮

v0.2.0 2023-01-17 10:28 UTC

This package is auto-updated.

Last update: 2024-09-17 13:50:33 UTC


README

轻松生成和渲染社交分享按钮

实时预览 https://laravel-share-to.prajwalhallale.com

安装

composer require prajwal89/laravel-share-to

如果你不使用自动发现,请将 ServiceProvider 添加到 config/app.php 文件中的 providers 数组
在 Laravel 5.5 及以上版本中不需要此步骤

// config/app.php
'providers' => [
    Prajwal89\LaravelShareTo\LaravelShareToServiceProvider::class,
];

发布资源

php artisan vendor:publish --provider="Prajwal89\LaravelShareTo\LaravelShareToServiceProvider"

运行数据库迁移

php artisan migrate

使用方法

use Prajwal89\LaravelShareTo\Share;

$options = [

    'tracking' => true, //this will keep track of share in track_shares table 

    //options for container
    'buttonGap' => 10, //in px
    'alignment' => 'center', // accepts (start|center|end) alignment of of buttons in container

    //options for button
    'borderWidth' => 2,
    'radius' => 4,
    'paddingX' => 4,
    'paddingY' => 8,
];

$share =  Share::Page('McqMate - MCQ Portal for Students', 'https://mcqmate.com', $options);

echo $share->all()->getButtons();

获取所有可用按钮

echo $share->all()->getButtons();

获取单个按钮

echo $share->facebook()->getButtons();

获取多个按钮

echo $share->whatsapp()->twitter()->getButtons();
//or
echo $share->only(['whatsapp','twitter'])->getButtons();

获取原始链接 这将返回一个包含分享 URL 的数组
你可以使用它来根据你的需求渲染按钮

echo $share->all()->getRawLinks();
//or
echo $share->only(['whatsapp','twitter'])->getRawLinks();

许可证

laravel-share-to 包是开源软件,遵循 MIT 许可证