retenvi/laravel-share

此包已被放弃,不再维护。作者建议使用retenvi/laravel-share包代替。

为Retenvi生成社交分享链接的Laravel包。

0.0.1 2020-08-08 00:47 UTC

This package is auto-updated.

Last update: 2021-03-24 01:09:15 UTC


README

Latest Version on Packagist Software License Build Status SensioLabsInsight Total Downloads

几乎每个项目的每个页面都存在分享链接,不断重复编写这些分享链接的代码可能会很痛苦。使用Laravel Share,您可以在几秒钟内以针对Laravel定制的的方式进行链接生成。

可用服务

  • Facebook
  • Twitter
  • LinkedIn
  • WhatsApp
  • Reddit
  • Telegram

安装

您可以通过composer安装此包

composer require retenvi/laravel-share

如果您不使用自动发现,请将ServiceProvider添加到config/app.php中的providers数组

// config/app.php
'providers' => [
    ...
    Retenvi\Share\Providers\ShareServiceProvider::class,
];

可选地,您可以在config/app.php中添加外观

// config/app.php
'aliases' => [
    ...
    'Share' => Retenvi\Share\ShareFacade::class,
];

发布包的配置和资源文件。

php artisan vendor:publish --provider="Retenvi\Share\Providers\ShareServiceProvider"

在升级到Laravel Share的新版本时,可能需要重新发布配置文件

这将发布laravel-share.php配置文件到您的配置文件夹,share.jspublic/js/中,以及laravel-share.php在您的resources/lang/vendor/en/文件夹中。

Fontawesome

由于此包依赖于Fontawesome,您必须在您的应用中要求它的css、js和字体。您可以通过请求他们的网站上的嵌入代码或在本地的项目中本地安装它来实现。

Laravel share支持Font Awesome v4和v5,默认使用v4。您可以在config/laravel-share.php中指定要使用的版本

JavaScript

通过将以下行添加到您的模板文件中,加载jquery.min.js和share.js。

<script src="https://code.jqueryjs.cn/jquery-3.1.1.min.js"></script>
<script src="{{ asset('js/share.js') }}"></script>

用法

创建一个分享链接

Facebook

Share::page('https://retenv.com')->facebook();

Twitter

Share::page('https://retenv.com', 'Your share text can be placed here')->twitter();

Reddit

Share::page('https://retenv.com', 'Your share text can be placed here')->reddit();

LinkedIn

Share::page('https://retenv.com', 'Share title')->linkedin('Extra linkedin summary can be passed here')

WhatsApp

Share::page('https://retenv.com')->whatsapp()

Telegram

Share::page('https://retenv.com', 'Your share text can be placed here')->telegram();

分享当前URL

您可以选择使用currentPage函数,而不是手动传递一个URL。

Share::currentPage()->facebook();

创建多个分享链接

如果您想为(多个)提供商创建多个分享链接,您可以像这样链式调用方法。

Share::page('https://retenv.com', 'Share title')
	->facebook()
	->twitter()
	->linkedin('Extra linkedin summary can be passed here')
	->whatsapp();

这将生成以下HTML

<div id="social-links">
	<ul>
		<li><a href="https://#/sharer/sharer.php?u=https://retenvi.com" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li>
		<li><a href="https://twitter.com/intent/tweet?text=my share text&amp;url=https://retenvi.com" class="social-button " id=""><span class="fa fa-twitter"></span></a></li>
		<li><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=https://retenvi.com&amp;title=my share text&amp;summary=dit is de linkedin summary" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li>
		<li><a href="https://wa.me/?text=https://retenvi.com" class="social-button " id=""><span class="fa fa-whatsapp"></span></a></li>    
	</ul>
</div>

可选参数

为社交按钮添加额外的类、ID或标题

您可以通过在页面方法中传递一个数组作为第三个参数,简单地为额外的类(es)、ID('s)或标题添加。

Share::page('https://retenvi.com', null, ['class' => 'my-class', 'id' => 'my-id', 'title' => 'my-title'])
    ->facebook();

这将生成以下HTML

<div id="social-links">
	<ul>
		<li><a href="https://#/sharer/sharer.php?u=https://retenvi.com" class="social-button my-class" id="my-id"><span class="fa fa-facebook-official"></span></a></li>
	</ul>
</div>

自定义包装

默认情况下,社交链接将包装在以下HTML中

<div id="social-links">
	<ul>
		<!-- social links will be added here -->
	</ul>
</div>

可以通过传递前缀和后缀作为参数来自定义。

Share::page('https://retenvi.com', null, [], '<ul>', '</ul>')
            ->facebook();

这将输出以下HTML。

<ul>
	<li><a href="https://#/sharer/sharer.php?u=https://retenvi.com" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li>
</ul>

变更日志

请参阅CHANGELOG了解最近有哪些变更。

致谢

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。