What is the wrong #15162
-
PackageInfolist builder Package Version3.2.130 How can we help you?<?php
namespace App\Filament\Guest\Pages;
use App\Models\School\Result;
use Filament\Pages\Page;
use Filament\Infolists\Infolist;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Contracts\HasInfolists;
use Filament\Infolists\Concerns\InteractsWithInfolists;
class FormResultPage extends Page implements HasInfolists
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.guest.pages.form-result-page';
use InteractsWithInfolists;
public $result;
public function mount(): void
{
// $this->result = Result::find(1); // works fine
$this->result = Result::where('roll_no', 149202)->get(); // not working
}
public function resultInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->result)
->schema([
TextEntry::make('roll_no'),
RepeatableEntry::make('subjects')
->schema([
TextEntry::make('name'),
TextEntry::make('mark'),
]),
]);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
To fix it, use |
Beta Was this translation helpful? Give feedback.
-
Why did you comment on this line? If you need to output a grid of data on the page, maybe a Panel builder's resource is more proper for it. |
Beta Was this translation helpful? Give feedback.
Result::where('roll_no', 149202)->get()
returns a collection (Collection
).However, the
infolist->record
method expects a parameter of type\Illuminate\Database\Eloquent\Model
. This mismatch causes the error.To fix it, use
Result::where('roll_no', 149202)->first()
instead, as it returns a single model rather than a collection.