library items parent_id

This commit is contained in:
Benjamin Takats
2023-01-19 14:59:29 +01:00
parent b1073919df
commit d1d98b6c31
7 changed files with 77 additions and 12 deletions

View File

@@ -153,8 +153,14 @@ class LibraryItemTable extends DataTableComponent
public function builder(): Builder
{
$shouldBePublic = request()
->route()
->getName() !== 'library.table.lecturer';
?->route()
?->getName() !== 'library.table.lecturer';
if ($this->currentTab !== '*') {
$parentLibrary = Library::query()
->where('name', $this->currentTab)
->first();
}
return LibraryItem::query()
->with([
@@ -162,8 +168,16 @@ class LibraryItemTable extends DataTableComponent
'tags',
])
->whereHas('libraries', fn($query) => $query->where('libraries.is_public', $shouldBePublic))
->when($this->currentTab !== '*', fn($query) => $query->whereHas('libraries',
fn($query) => $query->where('libraries.name', $this->currentTab)))
->when($this->currentTab !== '*', fn($query) => $query
->whereHas('libraries',
fn($query) => $query
->where('libraries.name', $this->currentTab)
)
->orWhereHas('libraries',
fn($query) => $query
->where('libraries.parent_id', $parentLibrary->id)
)
)
->withCount([
'lecturer',
])