How to preload select

Hi i have a problem where i made mine select with down below code how i can now preload it? preload(true) is not working
Select::make('project_id')
->preload(true)
->label('Project')
->searchable()
->getSearchResultsUsing(function (string $search) use ($lang) {
return Project::with(['contents' => function ($query) use($lang) {
$query->where('language', $lang->value);
}])
->whereHas('contents', function ($query) use ($search, $lang) {
$query->where('title', 'like', "%{$search}%")->where('language', $lang->value);
})
->get()
->mapWithKeys(function ($project) use($lang) {
$firstTitle = $project->contents->where('language', $lang->value)->pluck('title')->first();
return [$project->id => $firstTitle];
});
})
->getOptionLabelUsing(function ($value) use($lang) {
$project = Project::with(['contents' => function ($query) use($lang) {
$query->where('language', $lang->value);
}])->find($value);
return $project ? $project->contents->pluck('title')->first() : '';
})
->required(),
Select::make('project_id')
->preload(true)
->label('Project')
->searchable()
->getSearchResultsUsing(function (string $search) use ($lang) {
return Project::with(['contents' => function ($query) use($lang) {
$query->where('language', $lang->value);
}])
->whereHas('contents', function ($query) use ($search, $lang) {
$query->where('title', 'like', "%{$search}%")->where('language', $lang->value);
})
->get()
->mapWithKeys(function ($project) use($lang) {
$firstTitle = $project->contents->where('language', $lang->value)->pluck('title')->first();
return [$project->id => $firstTitle];
});
})
->getOptionLabelUsing(function ($value) use($lang) {
$project = Project::with(['contents' => function ($query) use($lang) {
$query->where('language', $lang->value);
}])->find($value);
return $project ? $project->contents->pluck('title')->first() : '';
})
->required(),
5 Replies
mile4841
mile48415w ago
Here you can see code better
mile4841
mile48415w ago
No description
toeknee
toeknee5w ago
or just use the correct code formating and add php after the first three ''' You need to set the ->options(), you are not doing that and you are not setting it as a relationship.
mile4841
mile48415w ago
Okay i will try with options
Dennis Koch
Dennis Koch5w ago
I think preload only works with ->options()
Want results from more Discord servers?
Add your server