shuvroroy/filament-spatie-laravel-backup 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shuvroroy/filament-spatie-laravel-backup

Composer 安装命令:

composer require shuvroroy/filament-spatie-laravel-backup

包简介

This plugin is built on top of Spatie's Laravel-backup package

README 文档

README

PHP Version Require Latest Stable Version Total Downloads License

This package provides a Filament page that you can create backup of your application. You'll find installation instructions and full documentation on spatie/laravel-backup.

Screenshot 2023-08-05 at 2 42 10 PM

Installation

You can install the package via composer:

composer require shuvroroy/filament-spatie-laravel-backup

Publish the package's assets:

php artisan filament:assets

You can publish the lang file with:

php artisan vendor:publish --tag="filament-spatie-backup-translations"

Usage

You first need to register the plugin with Filament. This can be done inside of your PanelProvider, e.g. AdminPanelProvider.

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(FilamentSpatieLaravelBackupPlugin::make());
    }
}

If you want to override the default Backups page icon, heading then you can extend the page class and override the navigationIcon property and getHeading method and so on.

<?php

namespace App\Filament\Pages;

use Illuminate\Contracts\Support\Htmlable;
use ShuvroRoy\FilamentSpatieLaravelBackup\Pages\Backups as BaseBackups;

class Backups extends BaseBackups
{
    protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-cpu-chip';

    public function getHeading(): string | Htmlable
    {
        return 'Application Backups';
    }

    public static function getNavigationGroup(): ?string
    {
        return 'Core';
    }
}

Then register the extended page class on AdminPanelProvider class.

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use App\Filament\Pages\Backups;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                    ->usingPage(Backups::class)
            );
    }
}

Permissions Setup (for Creating, Downloading & Deleting backups)

If you're using Spatie Laravel Permission or Filament Shield, you need to manually define the permissions used by this backup panel.

Required Permissions

  • download-backup – Allows downloading existing backups.
  • delete-backup – Allows deleting backups from the panel.
  • create-backup – Allows creating new backups from the panel.

Seeder Example

You can create a seeder to register these permissions and assign them to a role:

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class BackupPermissionSeeder extends Seeder
{
    public function run(): void
    {
        // Create permissions
        $permissions = [
            'download-backup',
            'delete-backup',
            'create-backup',
        ];

        foreach ($permissions as $permission) {
            Permission::firstOrCreate(['name' => $permission]);
        }

        // Assign to a role (optional)
        $role = Role::firstOrCreate(['name' => 'backup']);
        $role->givePermissionTo($permissions);

        // Assign role to a user (optional)
        $user = \App\Models\User::find(1); // Change ID as needed
        
        if ($user && !$user->hasRole('backup')) {
            $user->assignRole('backup');
        }
    }
}

Run the seeder using:

php artisan db:seed --class=BackupPermissionSeeder

After this, users with the backup role will have full access to the backup panel.

Customising navigation

You can customise the navigation icon, label, group, and sort order directly on the plugin without extending the page class:

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                    ->navigationIcon('heroicon-o-cpu-chip')
                    ->navigationLabel('Backups')
                    ->navigationGroup('Settings')
                    ->navigationSort(3)
            );
    }
}

All navigation methods also accept closures for dynamic values:

FilamentSpatieLaravelBackupPlugin::make()
    ->navigationLabel(fn (): string => __('custom.backups'))
    ->navigationGroup(fn (): ?string => auth()->user()->isAdmin() ? 'Admin' : 'Tools')

Pass null to navigationGroup() to remove the page from any navigation group.

Customising the polling interval

You can customise the polling interval for the Backups by following the steps below:

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                    ->usingPolingInterval('10s') // default value is 4s
            );
    }
}

Customising the queue

You can customise the queue name for the Backups by following the steps below:

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                    ->usingQueue('my-queue') // default value is null
            );
    }
}

Customising the timeout

You can customise the timeout for the backup job by following the steps below:

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                    ->timeout(120) // default value is max_execution_time from php.ini, or 30s if it wasn't defined
            );
    }
}

For more details refer to the set_time_limit function.

You can also disable the timeout altogether to let the job run as long as needed:

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                    ->noTimeout()
            );
    }
}

Customising who can access the page

You can customise who can access the Backups page by adding an authorize method to the plugin. The method should return a boolean indicating whether the user is authorised to access the page.

<?php

namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use ShuvroRoy\FilamentSpatieLaravelBackup\FilamentSpatieLaravelBackupPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentSpatieLaravelBackupPlugin::make()
                     ->authorize(fn (): bool => auth()->user()->email === 'admin@example.com'),
            );
    }
}

Upgrading

Please see UPGRADE for details on how to upgrade 1.X to 2.0.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

shuvroroy/filament-spatie-laravel-backup 适用场景与选型建议

shuvroroy/filament-spatie-laravel-backup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 435.38k 次下载、GitHub Stars 达 272, 最近一次更新时间为 2022 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel-backup」 「filament」 「filament-spatie-laravel-backup」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shuvroroy/filament-spatie-laravel-backup 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shuvroroy/filament-spatie-laravel-backup 我们能提供哪些服务?
定制开发 / 二次开发

基于 shuvroroy/filament-spatie-laravel-backup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 435.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 272
  • 点击次数: 25
  • 依赖项目数: 14
  • 推荐数: 0

GitHub 信息

  • Stars: 272
  • Watchers: 4
  • Forks: 62
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-02