PHP code example of itnia / laravel-pinnable

1. Go to this page and download the library: Download itnia/laravel-pinnable 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/ */

    

itnia / laravel-pinnable example snippets


use Itnia\Pinnable\Models\Concerns\HasPins;
use Itnia\Pinnable\Models\Concerns\Pinnable;
use Itnia\Pinnable\Models\Pin;

class Board extends Model
{
    use HasPins;
}

class Article extends Model
{
    use Pinnable;
}

$board->pin($article, auth()->user());
$board->unpin($article);
$article->isPinnedBy(auth()->user());
$article->isPinnedIn($board);

# with pins
$articles = Article::query()
    ->with(['pins' => fn($q) => $q->forOwner($board)])
    ->get();

use Itnia\Pinnable\Models\Concerns\HasPins;
use Itnia\Pinnable\Models\Concerns\Pinnable;
use Itnia\Pinnable\Models\Pin;

class User extends Model
{
    use HasPins;
}

class Article extends Model
{
    use Pinnable;
}

$user->pin($article);
$user->unpin($article);
$article->isPinnedIn($user);

# with attribute $article->is_pinned === true|false
$articles = Article::query()
    ->withExists(['pins as is_pinned' => fn($q) => $q->forOwner($user)])
    ->get();

Pin::forOwner($board)->forPinnable($article)->by($user)->first();
bash
composer vendor:publish --tag=pinnable-migrations
php artisan migrate