diff --git a/app/Http/Livewire/School/EventTable.php b/app/Http/Livewire/School/EventTable.php index 10f397e3..e6b84c3b 100644 --- a/app/Http/Livewire/School/EventTable.php +++ b/app/Http/Livewire/School/EventTable.php @@ -42,6 +42,10 @@ class EventTable extends Component 'coords' => [$event->venue->city->latitude, $event->venue->city->longitude], ]), 'events' => CourseEvent::query() + ->with([ + 'course', + 'venue.city.country', + ]) ->where('from', '>=', now()) ->get() ->map(fn($event) => [ diff --git a/app/Http/Livewire/Tables/BookCaseTable.php b/app/Http/Livewire/Tables/BookCaseTable.php index 4fa8c0cf..1ca9680c 100644 --- a/app/Http/Livewire/Tables/BookCaseTable.php +++ b/app/Http/Livewire/Tables/BookCaseTable.php @@ -27,8 +27,8 @@ class BookCaseTable extends DataTableComponent 'date' => null, 'comment' => '', ]; - protected $model = BookCase::class; public string $tableName = 'bookcases'; + protected $model = BookCase::class; public function configure(): void { @@ -121,6 +121,9 @@ class BookCaseTable extends DataTableComponent public function builder(): Builder { return BookCase::query() + ->with([ + 'orangePills', + ]) ->withCount([ 'orangePills', ]); diff --git a/app/Http/Livewire/Tables/CourseTable.php b/app/Http/Livewire/Tables/CourseTable.php index 18c4c9e6..0a723786 100644 --- a/app/Http/Livewire/Tables/CourseTable.php +++ b/app/Http/Livewire/Tables/CourseTable.php @@ -12,9 +12,8 @@ use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter; class CourseTable extends DataTableComponent { public string $country; - - protected $model = Course::class; public string $tableName = 'courses'; + protected $model = Course::class; public function configure(): void { @@ -89,6 +88,10 @@ class CourseTable extends DataTableComponent public function builder(): Builder { return Course::query() + ->with([ + 'lecturer', + 'tags', + ]) ->withCount([ 'courseEvents', ]) diff --git a/app/Http/Livewire/Tables/EventTable.php b/app/Http/Livewire/Tables/EventTable.php index 6016d89b..8fc18a83 100644 --- a/app/Http/Livewire/Tables/EventTable.php +++ b/app/Http/Livewire/Tables/EventTable.php @@ -17,8 +17,8 @@ class EventTable extends DataTableComponent public string $country; public bool $viewingModal = false; public $currentModal; - protected $model = CourseEvent::class; public string $tableName = 'events'; + protected $model = CourseEvent::class; public function configure(): void { @@ -26,7 +26,7 @@ class EventTable extends DataTableComponent ->setPrimaryKey('id') ->setDefaultSort('from', 'asc') ->setAdditionalSelects([ - 'id', + 'course_events.id', 'course_id', 'venue_id', ]) @@ -165,8 +165,9 @@ class EventTable extends DataTableComponent public function builder(): Builder { return CourseEvent::query() - ->withCount([ - 'registrations', + ->with([ + 'course.lecturer', + 'course.categories', ]) ->where('from', '>=', now()) ->whereHas('venue.city.country', diff --git a/app/Http/Livewire/Tables/LibraryItemTable.php b/app/Http/Livewire/Tables/LibraryItemTable.php index 89ad340d..1a78c4d3 100644 --- a/app/Http/Livewire/Tables/LibraryItemTable.php +++ b/app/Http/Livewire/Tables/LibraryItemTable.php @@ -9,7 +9,6 @@ use App\Models\Tag; use Illuminate\Database\Eloquent\Builder; use Rappasoft\LaravelLivewireTables\DataTableComponent; use Rappasoft\LaravelLivewireTables\Views\Column; -use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn; use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter; use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter; use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter; @@ -18,8 +17,8 @@ use Spatie\LaravelOptions\Options; class LibraryItemTable extends DataTableComponent { public string $currentTab; - protected $model = LibraryItem::class; public string $tableName = 'library_items'; + protected $model = LibraryItem::class; public function configure(): void { @@ -159,6 +158,10 @@ class LibraryItemTable extends DataTableComponent ->getName() !== 'library.table.lecturer'; return LibraryItem::query() + ->with([ + 'lecturer', + '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))) diff --git a/app/Http/Livewire/Tables/MeetupTable.php b/app/Http/Livewire/Tables/MeetupTable.php index 2c17457c..77945f6b 100644 --- a/app/Http/Livewire/Tables/MeetupTable.php +++ b/app/Http/Livewire/Tables/MeetupTable.php @@ -11,9 +11,8 @@ use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter; class MeetupTable extends DataTableComponent { public ?string $country = null; - - protected $model = Meetup::class; public string $tableName = 'meetups'; + protected $model = Meetup::class; public function configure(): void { @@ -72,6 +71,11 @@ class MeetupTable extends DataTableComponent public function builder(): Builder { return Meetup::query() + ->with([ + 'users', + 'city.country', + 'meetupEvents', + ]) ->when($this->country, fn($query, $country) => $query->whereHas('city.country', fn($query) => $query->where('code', $this->country))) ->withCount([ diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 01314a22..a6231403 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -5,6 +5,7 @@ namespace App\Providers; use App\Models\Episode; use App\Observers\EpisodeObserver; use App\Support\Carbon; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Date; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -29,6 +30,8 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { + Model::preventLazyLoading(); + Stringable::macro('initials', function () { $words = preg_split("/\s+/", $this); $initials = "";