Closed Quarasique closed 2 weeks ago
@Quarasique currently not. I used the state to store the uuid of the media record in previous versions, but due to a refactor of filament this was no longer possible because the media is saved after the page record, so you would need an extra save on the page (or whatever your model is).
What I do to avoid unnecessary media queries is making my own media model where I apply laravel-model-caching. This caches the media queries. Important: you need to disable the model caching for the filament routes (with for instance a middleware, I can send you an example), because the caching will fool with data updates in your filament forms.
@Quarasique Here is the middleware I am using to disable the model caching. You can apply this middleware on the panel in the filament service provider.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Symfony\Component\HttpFoundation\Response;
class DisableModelCache
{
/**
* Disable all model caching.
* Used in Filament to avoid showing cached data in Filament forms.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
Config::set('laravel-model-caching.enabled', false);
return $next($request);
}
}
@Quarasique Here is the middleware I am using to disable the model caching. You can apply this middleware on the panel in the filament service provider.
Thanks, it may be useful
There is no more questions, so we can close the issue)
Hi!
How can I retrieve the image ID after updating the package version?
Here’s my code:
In version 2.0.2, the preview attribute saved as "preview": "a9fab6dc-a400-4333-8b97-0352f4c5e1ad" in JSON within the content_blocks column. However, in version 2.1.5, it’s missing, which forces me to manually check the media table for the image existence by block_id. This adds extra and unnecessary database queries, which is quite frustrating.
Is there a way to retrieve the image ID directly or work around this?