PHP code example of postsimple / filament-postsimple

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

    

postsimple / filament-postsimple example snippets


use PostSimple\FilamentPostSimple\FilamentPostSimplePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugins([
            FilamentPostSimplePlugin::make(),
        ]);
}

use PostSimple\FilamentPostSimple\Actions\SendToPostSimpleAction;

protected function getHeaderActions(): array
{
    return [
        SendToPostSimpleAction::make(),
        // ... other actions
    ];
}

use PostSimple\FilamentPostSimple\Actions\SendToPostSimpleTableAction;

public static function table(Table $table): Table
{
    return $table
        ->columns([
            // ... your columns
        ])
        ->actions([
            SendToPostSimpleTableAction::make(),
            // ... other actions
        ]);
}



namespace App\Filament\Resources\PostResource\Pages;

use App\Filament\Resources\PostResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use PostSimple\FilamentPostSimple\Actions\SendToPostSimpleAction;

class EditPost extends EditRecord
{
    protected static string $resource = PostResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\DeleteAction::make(),
            SendToPostSimpleAction::make(), // Add this line
        ];
    }
}

// Works automatically - has 'title' field
class Post extends Model {
    protected $fillable = ['title', 'content'];
}

// Works automatically - has 'name' field  
class Product extends Model {
    protected $fillable = ['name', 'price'];
}

// Needs customization - has different field
class Article extends Model {
    protected $fillable = ['headline', 'body'];
}
// Use: ->titleAttribute('headline')

class Post extends Model
{
    protected $fillable = ['title', 'slug', 'content'];

    // Add this method to your model
    public function getUrl(): string
    {
        return url('/blog/' . $this->slug);
    }
}

class Product extends Model
{
    public function getUrl(): string
    {
        return route('products.show', $this);
    }
}

SendToPostSimpleTableAction::make()
    ->titleAttribute('product_name')
    ->urlUsing(fn ($record) => 'https://shop.example.com/products/' . $record->sku)

SendToPostSimpleAction::make()
    ->titleAttribute('product_name') // Use 'product_name' instead of 'title'

SendToPostSimpleTableAction::make()
    ->urlUsing(fn ($record) => route('shop.product', $record))

use PostSimple\FilamentPostSimple\Actions\SendToPostSimpleTableAction;

public static function table(Table $table): Table
{
    return $table
        ->columns([
            Tables\Columns\TextColumn::make('product_name'),
            Tables\Columns\TextColumn::make('sku'),
        ])
        ->actions([
            SendToPostSimpleTableAction::make()
                ->titleAttribute('product_name') // Custom title field
                ->urlUsing(fn ($record) => route('shop.product', $record->slug)), // Custom URL
        ]);
}

SendToPostSimpleAction::make()
    ->titleAttribute('custom_heading')
    ->urlUsing(function ($record) {
        return config('app.frontend_url') . '/posts/' . $record->id;
    })

return [
    // Your PostSimple API key ('),

    // API endpoint (don't change unless instructed)
    'api_endpoint' => env('POSTSIMPLE_API_ENDPOINT', 'https://postsimple.link/api/plugins/create-post'),

    // PostSimple app URL
    'app_url' => env('POSTSIMPLE_APP_URL', 'https://my.postsimple.app/lab'),

    // Request timeout (seconds)
    'timeout' => env('POSTSIMPLE_TIMEOUT', 30),
];
bash
php artisan vendor:publish --tag="filament-postsimple-config"
bash
php artisan vendor:publish --tag="filament-postsimple-lang"