1. Go to this page and download the library: Download edulazaro/laracrate 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/ */
'urls' => [
'signed_ttl' => 5, // signed URL TTL in minutes (R2)
'signed_cache_ttl' => 4, // server-side cache TTL of the signed URL
'sensitive_redirect_ttl' => 10, // ultra-short TTL after validation (seconds)
'route_signed_ttl' => 15, // HMAC TTL for /files/{slug}/stream (minutes)
'bind_to_user' => true, // tie the URL to the current viewer when sensitive
],
// AppServiceProvider::boot()
$registry = app(\EduLazaro\Laracrate\Support\FileActionRegistry::class);
// Add your own step
$registry->add(new \App\Files\Pipeline\VirusScanStep());
// Remove a default
$registry->remove(\EduLazaro\Laracrate\Pipeline\Steps\Image\OptimizeImageStep::class);
'collections' => [
'documents' => [
// ...
'actions' => [
\App\Pipeline\Steps\ClassifyDocumentStep::class,
],
'models' => [
// Optional: extra steps that only apply when the fileable
// is a specific morph type. Cumulative with the top-level
// 'actions' above — both run.
'case' => ['actions' => [\App\Pipeline\Steps\DetectDeadlinesStep::class]],
'lawsuit' => ['actions' => [\App\Pipeline\Steps\AutofillLawsuitStep::class]],
],
],
],
namespace App\Files\Pipeline;
use App\Files\Actions\VirusScanAction;
use EduLazaro\Laracrate\Contracts\FileActionInterface;
use EduLazaro\Laracrate\Models\File;
use EduLazaro\Laractions\Action;
class VirusScanStep extends Action implements FileActionInterface
{
public function supports(File $file): bool
{
return $file->creator_type === 'user'
&& in_array($file->collection, ['documents', 'attachments'], true);
}
public function priority(): int
{
return 5;
}
public function handle(File $file): void
{
VirusScanAction::create()->run(['file' => $file]);
}
}
$file->key // ltrim($file->path, '/'), the full key
$file->variantKey($newName) // build the key for a variant (variants/ subdir)
$file->siblingKey($newName) // build the key for a sibling (same dir)
$file->createVariant($name, $overrides) // create a variant row inheriting parent scope
// Relations
$file->parent
$file->children
$file->fileable
$file->creator
$file->tenant
$file->contents // chunks from laracrate_file_contents
// Variants
$file->variant('preview.thumbnail') // dot notation, falls back to ancestor
$file->variantOrFail('preview.thumbnail') // throws if the chain breaks
// URLs
$file->url($forceType = null) // real URL or placeholder
$file->link // accessor: alias of url()
$file->preview_link // accessor: variant('preview.thumbnail')->url('image')
$file->streamUrl()
$file->downloadUrl()
$file->placeholderFor('image')
// Storage
$file->key // accessor: ltrim(path, '/')
$file->variantKey($newName)
$file->siblingKey($newName)
$file->createVariant($variantName, $overrides)
// State
$file->makeDefault()
$file->publish() / unpublish()
$file->isVariant() / isTopLevel() / isSensitive()
$file->isImage() / isVideo() / isAudio() / isDocument()
$file->createdByUser() / createdByAgent() / createdAutomatically()
// Extracted text (when embed)
$file->extractedText(): ?string // joins all chunks
$file->hasEmbeddings(): bool
// Authorization (delegates to PolicyRegistry)
$file->canView($user)
$file->canEdit($user)
$file->canDelete($user)
// Scopes
File::published()
File::unpublished()
File::default()
File::ordered()
File::topLevel()
File::withDescendants(2)
File::forTenant($tenant)
$manager = app(\EduLazaro\Laracrate\Services\StorageManager::class);
$manager->urlFor($file) // delegates to GeneratePublicUrl/Signed/Stream
$manager->diskFor($file) // Storage::disk for the File
$manager->readBinary($file) // full binary contents
$manager->writeBinary($disk, $key, $content, $mime)
$manager->deleteFromBackend($disk, $key)
$manager->moveServerSide($disk, $fromKey, $toKey) // S3 copyObject
$manager->batchDelete($disk, $keys) // up to 1000 keys per request
$manager->presignedUpload($disk, $key, $mime, $maxSize, $minutes = 15)
$manager->withLocalCopy($file, $callback) // safe temporary download
$manager->getCollectionConfig($collection): array
$manager->getTypeConfig($collection, $type): array
$manager->acceptsType($collection, $type): bool
$manager->driverOf($disk): string
$manager->s3ClientOf($disk): ?S3Client
$usage = app(\EduLazaro\Laracrate\Services\UsageReporter::class);
$stats = $usage->forTenant($organization); // total bytes used by an org/tenant
$stats = $usage->forCreator($user); // total bytes uploaded by a user
$stats = $usage->forCollection('documents'); // total bytes in one collection
$stats->bytes // raw byte count (int)
$stats->files // number of files (int)
$stats->byCollection // ['avatar' => 12345, 'documents' => 9876543, ...]
$stats->human() // "1.42 GB"
$stats->exceeds($limit) // bool, useful for quota checks