PHP code example of roundly-consulting / posts-for-laravel

1. Go to this page and download the library: Download roundly-consulting/posts-for-laravel 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/ */

    

roundly-consulting / posts-for-laravel example snippets


use RoundlyConsulting\Posts\DataTransferObjects\SeoData;
use RoundlyConsulting\Posts\Facades\Posts;

$post = Posts::draft()
    ->title('en', 'Hello world')->title('sk', 'Ahoj svet')
    ->perex('en', 'A short intro')
    ->content('en', '<p>…</p>')
    ->by($user)                                   // any author model, bigint/uuid/ulid keyed
    ->tags(['laravel', 'php'])                    // found or created by name
    ->seo(new SeoData(canonical: 'https://example.test/hello-world'))
    ->publish();

$post->getTranslation('title', 'sk');             // 'Ahoj svet'

use RoundlyConsulting\Posts\Models\Post;

Posts::findBySlug('hello-world');                 // current locale → fallback → any locale
Posts::published()->latest('published_at')->paginate();
Posts::archive($post);                            // or unpublish() back to draft

Route::get('/posts/{post}', fn (Post $post) => view('posts.show', compact('post')))->name('posts.show');
bash
composer vendor:publish --tag="posts-migrations"
php artisan vendor:publish --tag="media-migrations"
php artisan vendor:publish --tag="likes-migrations"
php artisan vendor:publish --tag="reports-migrations"
php artisan vendor:publish --tag="approvals-migrations"
php artisan migrate