initial import
This commit is contained in:
71
app/Filament/Pages/InstallPluginPage.php
Normal file
71
app/Filament/Pages/InstallPluginPage.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class InstallPluginPage extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
|
||||
protected static string $view = 'filament.pages.install-plugin-page';
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
|
||||
protected static ?string $title = 'Install Plugin';
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->form->fill();
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
FileUpload::make('plugin_file')
|
||||
->label('Plugin File (.php)')
|
||||
->required()
|
||||
->acceptedFileTypes(['application/x-php'])
|
||||
->directory('temp_plugins')
|
||||
->disk('local'),
|
||||
])
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function submit(): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
|
||||
$uploadedFile = $data['plugin_file'];
|
||||
$filename = File::basename($uploadedFile);
|
||||
$destinationPath = app_path('Api/Plugins/' . $filename);
|
||||
|
||||
try {
|
||||
File::move(storage_path('app/temp_plugins/' . $filename), $destinationPath);
|
||||
|
||||
Notification::make()
|
||||
->title('Plugin installed successfully')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->form->fill(); // Clear the form
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->title('Error installing plugin')
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user