Very quick question about relationships.

Hey all I'm using the table builder.
TextColumn::make('users_exists')->exists('users')
TextColumn::make('users_exists')->exists('users')
What is best practice to add a where clausule and display a check if true? So in pseudo-code i mean something like this Display a check if a user exists where language_id = 1 .
10 Replies
RickDB
RickDB2y ago
Do you mean you want a Checkbox column based on whether the user has language_id 1 or not?
VIIKKK
VIIKKKOP2y ago
Sorry, the check was indeed open for interpretation. I meant a check icon from font-awesome. My question is basically how to render something custom based on a condition. and how I should query for the condition.
RickDB
RickDB2y ago
Ah yeah, you could add a Placeholder that returns a html string
VIIKKK
VIIKKKOP2y ago
Allright, and any pointers on how to add the where query?
RickDB
RickDB2y ago
You could add a closure to the ->content(), for example:
->content(function (callable $get) {
$user = User::find($get(user_id);

if($user->language = 1) {
return new HtmlString('language id is 1');
}

return new HtmlString('language id is not 1');
->content(function (callable $get) {
$user = User::find($get(user_id);

if($user->language = 1) {
return new HtmlString('language id is 1');
}

return new HtmlString('language id is not 1');
would something like this work for you?
VIIKKK
VIIKKKOP2y ago
Yeah, but i already tried something like that. I think i have another issue. When i run the content method on either a TextColumn or Column. An error gets thrown that these methods don't exist.
RickDB
RickDB2y ago
Wait it's in table?
VIIKKK
VIIKKKOP2y ago
So might have to check how it's installed. Already cleared cache and compiled views yes
RickDB
RickDB2y ago
Try IconColumn
IconColumn::make('is_featured')
->options([
'heroicon-o-x-circle',
'heroicon-o-pencil' => 'draft',
'heroicon-o-clock' => 'reviewing',
'heroicon-o-check-circle' => 'published',
])
IconColumn::make('is_featured')
->options([
'heroicon-o-x-circle',
'heroicon-o-pencil' => 'draft',
'heroicon-o-clock' => 'reviewing',
'heroicon-o-check-circle' => 'published',
])
VIIKKK
VIIKKKOP2y ago
oh yeah that works. i'll check the documentation to find out where to add the conditional logic
Want results from more Discord servers?
Add your server