mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
library items parent_id
This commit is contained in:
@@ -26,6 +26,7 @@ class LibraryTable extends Component
|
||||
}
|
||||
|
||||
$libraries = \App\Models\Library::query()
|
||||
->whereNull('parent_id')
|
||||
->where('is_public', $shouldBePublic)
|
||||
->get();
|
||||
$tabs = collect([
|
||||
|
||||
@@ -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',
|
||||
])
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Library extends Model
|
||||
{
|
||||
@@ -44,4 +45,9 @@ class Library extends Model
|
||||
{
|
||||
return $this->belongsToMany(LibraryItem::class);
|
||||
}
|
||||
|
||||
public function parent() : BelongsTo
|
||||
{
|
||||
return $this->belongsTo(__CLASS__, 'parent_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,6 @@ class Library extends Resource
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'name';
|
||||
|
||||
public static function label()
|
||||
{
|
||||
return __('Library');
|
||||
}
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
* @var array
|
||||
@@ -41,6 +35,15 @@ class Library extends Resource
|
||||
'name',
|
||||
];
|
||||
|
||||
public static $with = [
|
||||
'createdBy',
|
||||
];
|
||||
|
||||
public static function label()
|
||||
{
|
||||
return __('Library');
|
||||
}
|
||||
|
||||
public static function afterCreate(NovaRequest $request, Model $model)
|
||||
{
|
||||
\App\Models\User::find(1)
|
||||
@@ -68,6 +71,10 @@ class Library extends Resource
|
||||
ID::make()
|
||||
->sortable(),
|
||||
|
||||
BelongsTo::make(__('Parent'), 'parent', __CLASS__)
|
||||
->searchable()
|
||||
->nullable(),
|
||||
|
||||
Text::make('Name')
|
||||
->rules('required', 'string'),
|
||||
|
||||
@@ -86,7 +93,8 @@ class Library extends Resource
|
||||
return $request->user()
|
||||
->hasRole('super-admin');
|
||||
})
|
||||
->searchable()->withSubtitles(),
|
||||
->searchable()
|
||||
->withSubtitles(),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ class LibraryItem extends Resource
|
||||
'name',
|
||||
];
|
||||
|
||||
public static $with = [
|
||||
'lecturer',
|
||||
'tags',
|
||||
];
|
||||
|
||||
public static function label()
|
||||
{
|
||||
return __('Library Item');
|
||||
|
||||
@@ -30,7 +30,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//Model::preventLazyLoading();
|
||||
Model::preventLazyLoading(app()->environment('local'));
|
||||
|
||||
Stringable::macro('initials', function () {
|
||||
$words = preg_split("/\s+/", $this);
|
||||
|
||||
Reference in New Issue
Block a user