lukaveck1
lukaveck1
FFilament
Created by lukaveck1 on 3/28/2025 in #❓┊help
Can't download PDF using Spatie Laravel-pdf
https://www.youtube.com/watch?v=QjoIpJj8qxU Reading the comments right now, sounds like this is a bit tricky after all.
2 replies
FFilament
Created by lukaveck1 on 3/27/2025 in #❓┊help
Having to click action button twice for changes to take place
Ty, one day in future you are getting donation so you have a nice dinner on me for all your help :D!
8 replies
FFilament
Created by lukaveck1 on 3/27/2025 in #❓┊help
Having to click action button twice for changes to take place
I found one thing that works, basically add: protected $listeners = ['myRefresh' => '$refresh']; and add in action $this->dispatch('myRefresh');
8 replies
FFilament
Created by lukaveck1 on 3/27/2025 in #❓┊help
Having to click action button twice for changes to take place
not sure how to make this work with $set and $get, view() method can't take closure as parameter
8 replies
FFilament
Created by lukaveck1 on 3/27/2025 in #❓┊help
Having to click action button twice for changes to take place
No description
8 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
That doesn't really solve anything, I'll keep the workaround for now and try with Spatie Media Upload as you suggested when I have time.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
But thanks for giving me directions, I think that's my knowledge hole in this whole thing and what I should be doing in the first place.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I have relationship manager where I'm returning my AssetUpload class, not sure where to explode these things now:
class ProfileBaseAssetsRelationManager extends BaseAssetsRelationManager
{
public static string $assetDirectory = 'profile-assets';

public string $assetLabel = 'Profile assets';

public function form(Form $form): Form
{
return $form
->schema([
AssetUpload::make($this->assetLabel, self::$assetDirectory),
]);
}
class ProfileBaseAssetsRelationManager extends BaseAssetsRelationManager
{
public static string $assetDirectory = 'profile-assets';

public string $assetLabel = 'Profile assets';

public function form(Form $form): Form
{
return $form
->schema([
AssetUpload::make($this->assetLabel, self::$assetDirectory),
]);
}
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I don't have a zip (attachement) of assets, I have separate assets on their own
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I'll check it out now. Here'es recording so we understand what's the problem - again for each record it saves all filenames of uploaded files instead of one by one.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I'll check
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
Yes, I have to save filenames, but I don't need that method for it on FileUpload.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
What's even weirder is that I can't find a working example online as docs say.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
It was a quick 20min added feature at first, but with new demands this got ugly after trying to implement storing multiple files with filenames.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
Well this was already implemented as said and worked good for other resource (but saving filenames there wasn't necessary) and then when I started to implement it for another resource the docs seemed pretty straight forward on how it should work if we have separate column for filenames, but then I just couldn't get it to work.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I know that creating() method looks weird, but that's how it was done by someone else for some other resource where we are uploading assets, but I had to do it on some other resource now as well, but with filenames stored separately. I tried to tweak it for my cause, but to no success.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I really tried everything to avoid doing this on created() method, because it should be pretty straight forward, but it isn't.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
class AssetObserver
{
public function created(Asset $asset) {
if ($this->resourceType($asset) === Profile::class) {
$this->updateFilename($asset);
}
}

/**
* Handle the Asset "creating" event.
*/
public function creating(Asset $asset): void
{
$urls = $asset->getAttribute('url');

if (is_array($urls) && count($urls) > 0) {
$firstUrl = array_shift($urls);
$asset->setAttribute('url', $firstUrl);

foreach ($urls as $url) {
$newAsset = clone $asset;
$newAsset->setAttribute('url', $url);
$newAsset->setAttribute('account_id', null);
$newAsset->save();
}
}
}

//TODO: This is ugly hack to set correct filename on profile assets, because doing it in creating() method didn't work correctly - there's weird behaviour when uploading multiple files. Doing it as docs say doesn't work https://filamentphp.com/docs/3.x/forms/fields/file-upload#storing-original-file-names-independently

protected function updateFilename($asset) {
$asset->update(['filename' => $this->parseFilename($asset->getAttribute('url'), $asset->getAttribute('filename'))]);

}

protected function parseFilename($url, $filenames) {
return array_filter($filenames, function ($key) use ($url) {
return $key === $url;
}, ARRAY_FILTER_USE_KEY);
}

protected function resourceType($asset) {
return $asset->getAttribute('resourceable_type');
}
}
class AssetObserver
{
public function created(Asset $asset) {
if ($this->resourceType($asset) === Profile::class) {
$this->updateFilename($asset);
}
}

/**
* Handle the Asset "creating" event.
*/
public function creating(Asset $asset): void
{
$urls = $asset->getAttribute('url');

if (is_array($urls) && count($urls) > 0) {
$firstUrl = array_shift($urls);
$asset->setAttribute('url', $firstUrl);

foreach ($urls as $url) {
$newAsset = clone $asset;
$newAsset->setAttribute('url', $url);
$newAsset->setAttribute('account_id', null);
$newAsset->save();
}
}
}

//TODO: This is ugly hack to set correct filename on profile assets, because doing it in creating() method didn't work correctly - there's weird behaviour when uploading multiple files. Doing it as docs say doesn't work https://filamentphp.com/docs/3.x/forms/fields/file-upload#storing-original-file-names-independently

protected function updateFilename($asset) {
$asset->update(['filename' => $this->parseFilename($asset->getAttribute('url'), $asset->getAttribute('filename'))]);

}

protected function parseFilename($url, $filenames) {
return array_filter($filenames, function ($key) use ($url) {
return $key === $url;
}, ARRAY_FILTER_USE_KEY);
}

protected function resourceType($asset) {
return $asset->getAttribute('resourceable_type');
}
}
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I did it with a very ugly hack, but this seems like a bug on filament side of things. By default it doesn't work, so I resorted to observer creating() method, which I thought is gonna work fine, just pass in the filename, but I got a very weird bug basically. One of the files would incorrectly save filename always when uploading multiple files (it would save all the filenames of uploaded files, instead of just one). Lastly I just said to update the name after record is created and this works as intended now.
34 replies
FFilament
Created by lukaveck1 on 3/25/2025 in #❓┊help
Storing multiple filenames at once when uploading multiple files
I have two columns in DB, one column 'url' and one 'filename', but it doesn't work.
34 replies