PHP code example of jncinet / laravel-share

1. Go to this page and download the library: Download jncinet/laravel-share library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jncinet / laravel-share example snippets


// ...
use Jncinet\LaravelShare\Traits\Sharer;

class User extends Authenticatable
{
    use Sharer;
    
    // ...
}

$user = User::find(1);
$article = Article::find(1);
// 分享文章
$user->share($article);
// 删除分享文章
$user->unShare($article);
// 获取所有分享的文章
$user->getShareItems(Article::class)
// 会员是否分享了文章
$user->hasShared($article); 

// ...
use Jncinet\LaravelShare\Traits\Shareable;

class Article extends Model
{
    use Shareable;
    
    // ...
}

$user = User::find(1);
$article = Article::find(1);
// 内容是否被用户分享过
$article->isSharedBy($user);
// 文章分享记录
$article->shares;
// 分享过内容的会员
$article->sharers;
shell
$ php artisan vendor:publish --provider="Jncinet\\LaravelShare\\ShareServiceProvider"