Melomancheto
Melomancheto
FFilament
Created by Melomancheto on 11/21/2024 in #❓┊help
Upload image/video to server right after it's been added as temp file
Hello everyone, I'm trying to find the right event to hook into that would help me to store the image right after it's been validated. I'm looking for something like afterValidation() I guess. I have the following component
SpatieMediaLibraryFileUpload::make('file')
->label('Media')
->previewable()
->acceptedFileTypes([
'image/jpeg',
'image/png',
'image/webp',
'video/mp4',
'video/webm',
'video/x-ms-wmv',
'video/quicktime'
])
->maxSize(1024 * 1024)
->disk(fn() => app()->environment('production') ? 's3' : 'public')
->imageEditor()
->image()
->directory(Filament::getTenant()->slug . DIRECTORY_SEPARATOR . 'media')
->moveFiles()
->afterStateHydrated(function (TemporaryUploadedFile $file) {
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$size = $file->getSize();
$mimeType = $file->getMimeType();

// Perform custom logic here (e.g., logging or additional processing)
\Log::info('Uploaded File Metadata:', [
'name' => $originalName,
'extension' => $extension,
'size' => $size,
'mime_type' => $mimeType,
]);
})
->required()
SpatieMediaLibraryFileUpload::make('file')
->label('Media')
->previewable()
->acceptedFileTypes([
'image/jpeg',
'image/png',
'image/webp',
'video/mp4',
'video/webm',
'video/x-ms-wmv',
'video/quicktime'
])
->maxSize(1024 * 1024)
->disk(fn() => app()->environment('production') ? 's3' : 'public')
->imageEditor()
->image()
->directory(Filament::getTenant()->slug . DIRECTORY_SEPARATOR . 'media')
->moveFiles()
->afterStateHydrated(function (TemporaryUploadedFile $file) {
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$size = $file->getSize();
$mimeType = $file->getMimeType();

// Perform custom logic here (e.g., logging or additional processing)
\Log::info('Uploaded File Metadata:', [
'name' => $originalName,
'extension' => $extension,
'size' => $size,
'mime_type' => $mimeType,
]);
})
->required()
What would the best event to replace afterStateHydrated() here?
2 replies
FFilament
Created by Melomancheto on 11/11/2024 in #❓┊help
Multi-tenancy for models with no direct relation to user
If I understand the multi-tenancy I always need to pass the organization relation, since this is what my tenancy is referring to. Sadly at some models I don't have direct relation to the user or the user is a Many to Many or One to Many relation so that I can get to the organization. I get the following error. I already have set the tenant for the panel by using ->tenant(Organization::class, slugAttribute: 'slug'). I can change the Ownership of the Relationship Name for example protected static ?string $tenantOwnershipRelationshipName = 'users'; as per Resource but since I'm going from the Media -> Game -> User -> Organization this looks very complicated tbh. I've added the following code in Models/Media.php order to display something.

public function organization()
{
return $this->game()->with(
[
'user.organizations' => fn (Builder $builder) => $builder->where('organizations.id', Filament::getTenant()->id)
]
);
}

public function organization()
{
return $this->game()->with(
[
'user.organizations' => fn (Builder $builder) => $builder->where('organizations.id', Filament::getTenant()->id)
]
);
}
If I remove it I get the error from below. The error itself is very self explanatory but I still feel like I'm not doing something right.
The model [App\Models\GameMedia] does not have a relationship named [organization]. You can change the relationship being used by passing it to the [ownershipRelationship] argument of the [tenant()] method in configuration. You can change the relationship being used per-resource by setting it as the [$tenantOwnershipRelationshipName] static property on the [App\Filament\Resources\GameMediaResource] resource class.
The model [App\Models\GameMedia] does not have a relationship named [organization]. You can change the relationship being used by passing it to the [ownershipRelationship] argument of the [tenant()] method in configuration. You can change the relationship being used per-resource by setting it as the [$tenantOwnershipRelationshipName] static property on the [App\Filament\Resources\GameMediaResource] resource class.
If I understand correctly I need to go in every model and define the so called organization relationship and from there fetch the right organization going trough the user?
9 replies
FFilament
Created by Melomancheto on 11/7/2024 in #❓┊help
How to handle selected relations during creating a record in handleRecordCreation
No description
16 replies
FFilament
Created by Melomancheto on 11/5/2024 in #❓┊help
Define a custom route with custom view in Filament
I would like to define a custom logic that will be executed after the user logs in. The idea is to show a similar design to the login page after the user logins. It will contain a dropdown menu and a submit button. The problem is that I'm unable to define the custom route anywhere. Can you please guide me where should I put such behaviour?
10 replies