1. Go to this page and download the library: Download ijodkor/only-office 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/ */
ijodkor / only-office example snippets
namespace App\Http\Controllers;
use Illuminate\Contracts\View\View;
use OnlyOffice\Config\ConfigService;
use OnlyOffice\Config\OfficeConfig;
use OnlyOffice\DocServer\DocFile;
use OnlyOffice\DocServer\FileManagement\FileService;
class TemplateController {
public function __construct(
private FileService $fileService,
private ConfigService $configService
) {
}
public function create(): string {
$filename = "school/document.docx";
// File
$example = "new.docx";
$source = DocFile::getSourcePath($example);
// File path (/storage/app/private/templates/school/document.docx)
$path = $this->fileService->storeAs($source, $filename);
return $path;
}
public function show(): View {
$fileInfo = [
"directory" => "school",
"name" => "document.docx",
'path' => '/app/private/templates/school/document.docx'
];
$config = $this->configService->view([], $fileInfo, ConfigService::FILE_TYPE_DOCX);
return view('office::index', [
'config' => array_merge($config, [
'js' => OfficeConfig::getUrl()
])
]);
}
public function edit(): View {
$fileInfo = [
"directory" => "school",
"name" => "document.docx",
'path' => '/app/private/templates/school/document.docx'
];
$config = $this->configService->modify([], $fileInfo, ConfigService::FILE_TYPE_DOCX);
return view('office::index', [
'config' => array_merge($config, [
'js' => OfficeConfig::getUrl()
])
]);
}
}