I have custom page, I want to add a table and tabs as filters, but the tabs seems to not work when selected #12490
-
PackagePanel builder Package VersionV3.0.0 How can we help you?Here is my Page: <?php
namespace App\Filament\Student\Pages;
use App\Models\Course;
use Filament\Pages\Page;
use Filament\Tables\Table;
use Illuminate\Http\Response;
use Filament\Tables\Actions\Action;
use Filament\Forms\Contracts\HasForms;
use Filament\Resources\Components\Tab;
use Illuminate\Database\Query\Builder;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Contracts\HasTable;
use Filament\Resources\Concerns\HasTabs;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Tables\Concerns\InteractsWithTable;
class Courses extends Page implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;
use HasTabs;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.student.pages.courses';
public function getTabs(): array {
return [
'All Courses' => Tab::make()
->badge(fn () => Course::count()),
'Taken Courses' => Tab::make()
->badge(fn () => Course::whereHas('students', fn($q) => $q->where('id', auth()->id()))->count())
->modifyQueryUsing(function (Builder $q) {
info('i', [
'query' => $q->get()
]);
return $q->where('id', 6);
//$q->whereHas('students', fn($q)=> $q->id === auth()->id()
}),
];
}
public static function table(Table $table): Table
{
return $table
->query(Course::query())
->columns([
TextColumn::make('ccode')
->label("Course code")
->searchable(),
TextColumn::make('name')
->label('Course name')
->searchable(),
TextColumn::make('section.name')
->label("Section"),
TextColumn::make('seats')
->label('Available Seats'),
TextColumn::make('classroom.rcode')
->label('Classroom'),
TextColumn::make('start_time')
->time("H:i A")
->label('Start time'),
TextColumn::make('end_time')
->time("H:i A")
->label('End time'),
TextColumn::make('days')
->label("Week Days"),
TextColumn::make('mid_date')
->date()
->label('Midterm Date'),
TextColumn::make('final_date')
->date()
->label('Final Date'),
])
->filters([
//
])
->actions([
Action::make('Take the course')
->action(function (Course $course) {
$stdId = Auth()->id();
if ($course->students()->where('id', $stdId)->exists()) {
throw new \Exception("You have already taken the course!", Response::HTTP_CONFLICT);
}
$totalStd = $course->students()->count();
if($course->seats <= $totalStd) {
throw new \Exception("All the seats are occupied already!", Response::HTTP_FORBIDDEN);
}
$course->students()->create([
'student_id' => $stdId
]);
})
]);
}
}```
Here's is the page blade view:-
```blade
<x-filament-panels::page>
<x-filament-panels::resources.tabs />
{{ $this->table }}
</x-filament-panels::page> Any solution would be highly appreciated? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
did you find any solution? |
Beta Was this translation helpful? Give feedback.
-
i have same problem |
Beta Was this translation helpful? Give feedback.
-
I forgot but I found the solution, see this function: ->modifyQueryUsing(function (Builder $q) {
info('i', [
'query' => $q->get()
]);
return $q->where('id', 6);
//$q->whereHas('students', fn($q)=> $q->id === auth()->id()
}) Here the callback parameter It seems that Filamentphp passes the parameter as named parameter. That's why the we must use |
Beta Was this translation helpful? Give feedback.
I forgot but I found the solution, see this function:
Here the callback parameter
Builder $q
should beBuilder $query
It seems that Filamentphp passes the parameter as named parameter. That's why the we must use
$query
in it's full form. We cannot use any other name at all.