SpatieMediaLibraryPlugin with getTableQuery()

Hello all, I am using SpatieMediaLibraryPlugin for media collections. I have a user model where admin's can hold PDF, Word or Excel documents for a specific user. I want to show these files on a table but could not find how I can query the Media class in getTableQuery() function. Does anyone know a trick for it? Thanks.
2 Replies
Tin
Tin2y ago
$models = Model::whereHas('media', function ($query) { $query->where('name', 'like', '%your-media-name%'); })->get(); Are you looking for this?
onursahindur
onursahindurOP2y ago
Thanks for your tip. I managed to do that via tis code; protected function getTableQuery(): Builder { return Media::query()->where('model_type', User::class) ->where('model_id', $this->record) ->where('collection_name', User::$userDocumentsKey); }
Want results from more Discord servers?
Add your server