PHP code example of tomatophp / filament-cms-github

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

    

tomatophp / filament-cms-github example snippets


use TomatoPHP\FilamentCmsGithub\FilamentCmsGithubPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(FilamentCmsGithubPlugin::make());
}

use TomatoPHP\FilamentCmsGithub\Services\GitHubService;

$service = app(GitHubService::class);

$post = $service->importRepository(
    url: 'https://github.com/tomatophp/filament-cms',
    userId: auth()->id(),
    userType: get_class(auth()->user())
);

use TomatoPHP\FilamentCmsGithub\Services\GitHubService;
use TomatoPHP\FilamentCms\Models\Post;

$service = app(GitHubService::class);
$post = Post::find(1);

$success = $service->refreshPost($post);

use TomatoPHP\FilamentCmsGithub\Services\GitHubService;

$service = app(GitHubService::class);
$count = $service->refreshAllPosts(); // Returns number of posts refreshed

$repo = $service->extractRepoFromUrl('https://github.com/tomatophp/filament-cms');
// Returns: 'tomatophp/filament-cms'

$data = $service->fetchRepoData('tomatophp/filament-cms');
// Returns array with: id, name, full_name, description, stargazers_count, etc.

$readme = $service->fetchReadme('tomatophp/filament-cms', 'master');
// Returns: markdown content as string

$data = $service->fetchPackagistData('tomatophp/filament-cms');
// Returns array with downloads, versions, keywords, etc.

$post = $service->importRepository(
    url: 'https://github.com/tomatophp/filament-cms',
    userId: 1,
    userType: 'App\\Models\\User'
);

$success = $service->refreshPost($post);

$count = $service->refreshAllPosts();

use TomatoPHP\FilamentCmsGithub\Filament\Actions\GithubImportAction;

// In your resource
protected function getHeaderActions(): array
{
    return [
        GithubImportAction::make(),
    ];
}

use TomatoPHP\FilamentCmsGithub\Filament\Actions\GithubRefreshAction;

protected function getHeaderActions(): array
{
    return [
        GithubRefreshAction::make(),
    ];
}

[
    'title' => ['en' => 'Repository Name', 'ar' => 'Repository Name'],
    'slug' => 'repository-name',
    'body' => ['en' => '# README content...', 'ar' => '# README content...'],
    'short_description' => ['en' => 'Description', 'ar' => 'Description'],
    'keywords' => ['en' => 'keyword1,keyword2', 'ar' => 'keyword1,keyword2'],
    'type' => 'open-source',
    'meta_url' => 'https://github.com/owner/repo',
    'is_published' => true,
    'published_at' => now(),
]

$post = Post::find(1);

// Get star count
$stars = $post->meta('github_starts');

// Get total downloads
$downloads = $post->meta('downloads_total');

use TomatoPHP\FilamentCmsGithub\Jobs\GitHubMetaGetterJob;

dispatch(new GitHubMetaGetterJob(
    url: 'https://github.com/tomatophp/filament-cms',
    redirect: '/posts',
    userId: auth()->id(),
    userType: get_class(auth()->user()),
    panel: 'admin'
));

use TomatoPHP\FilamentCmsGithub\Jobs\GitHubMetaRefreshJob;

dispatch(new GitHubMetaRefreshJob);

use TomatoPHP\FilamentCms\Events\PostCreated;
use Illuminate\Support\Facades\Event;

Event::listen(PostCreated::class, function ($event) {
    $post = $event->model;

    // Custom processing here
    if ($post->type === 'open-source') {
        // Do something with imported repository
    }
});

use Illuminate\Support\Facades\Notification;
use TomatoPHP\FilamentCmsGithub\Jobs\GitHubMetaGetterJob;

class CustomNotificationHandler
{
    public function handle(GitHubMetaGetterJob $job)
    {
        // Custom notification logic
    }
}
bash
php artisan filament-cms-github:install
bash
# Run queue worker
php artisan queue:work
bash
php artisan vendor:publish --tag="filament-cms-github-config"
bash
php artisan vendor:publish --tag="filament-cms-github-views"
bash
php artisan vendor:publish --tag="filament-cms-github-lang"
bash
php artisan vendor:publish --tag="filament-cms-github-migrations"
bash
php artisan queue:work
bash
composer analyse