F
Filament•15mo ago
gigiloouu

error it cant see my table columns

It was working but now it doest works idk why.. when i create supplier it cant see brands and subbrands. there is my code also:
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->minLength(2),
Select::make('brand_id')
->label('Brand')
->multiple()
->relationship('brand', 'name')
->searchable()
->required()
->options(Brand::all()->pluck('name', 'id'))
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
]),
Select::make('subbrand_id')
->label('Subbrand')
->multiple()
->relationship('subbrand', 'name')
->searchable()
->options(Subbrand::all()->pluck('name', 'id'))
->columnSpan('full')
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Subbrand'),
]),
]);
}
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->minLength(2),
Select::make('brand_id')
->label('Brand')
->multiple()
->relationship('brand', 'name')
->searchable()
->required()
->options(Brand::all()->pluck('name', 'id'))
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
]),
Select::make('subbrand_id')
->label('Subbrand')
->multiple()
->relationship('subbrand', 'name')
->searchable()
->options(Subbrand::all()->pluck('name', 'id'))
->columnSpan('full')
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Subbrand'),
]),
]);
}
Supplier Model:
No description
No description
No description
49 Replies
gigiloouu
gigiloouuOP•15mo ago
any ideas?
ericmp
ericmp•15mo ago
not sure, but an optimisation:
Brand::all()->pluck('name', 'id')
Brand::all()->pluck('name', 'id')
to
Brand::pluck('name', 'id')
Brand::pluck('name', 'id')
\Illuminate\Support\Benchmark::dd([
fn () => Brand::all()->pluck('name', 'id'),
fn () => Brand::pluck('name', 'id'),
]);
\Illuminate\Support\Benchmark::dd([
fn () => Brand::all()->pluck('name', 'id'),
fn () => Brand::pluck('name', 'id'),
]);
gigiloouu
gigiloouuOP•15mo ago
where i should write this ?
\Illuminate\Support\Benchmark::dd([
fn () => Brand::all()->pluck('name', 'id'),
fn () => Brand::pluck('name', 'id'),
]);
\Illuminate\Support\Benchmark::dd([
fn () => Brand::all()->pluck('name', 'id'),
fn () => Brand::pluck('name', 'id'),
]);
ericmp
ericmp•15mo ago
in tinker for example - php artisan tinker add \App\Models\ before the model name
gigiloouu
gigiloouuOP•15mo ago
i should write it in model?
ericmp
ericmp•15mo ago
no, i mean, like this:
\Illuminate\Support\Benchmark::dd([
fn () => \App\Models\Brand::all()->pluck('name', 'id'),
fn () => \App\Models\Brand::pluck('name', 'id'),
]);
\Illuminate\Support\Benchmark::dd([
fn () => \App\Models\Brand::all()->pluck('name', 'id'),
fn () => \App\Models\Brand::pluck('name', 'id'),
]);
gigiloouu
gigiloouuOP•15mo ago
okay and where i should writ eit ? aa in terminal?
ericmp
ericmp•15mo ago
if u do php artisan tinker u can execute arbitrary code yes thats an option
gigiloouu
gigiloouuOP•15mo ago
No description
gigiloouu
gigiloouuOP•15mo ago
i got it what is it ? šŸ’€
ericmp
ericmp•15mo ago
the benchmark results xd
gigiloouu
gigiloouuOP•15mo ago
amm and its works or what? dd is it good ? ddd idk in web i have same result it cant read brand_ids and subbrand_ids
gigiloouu
gigiloouuOP•15mo ago
No description
gigiloouu
gigiloouuOP•15mo ago
its doest takes brand_id and subbrand_id literally yesterday it was working dd just i remove db and create again but in db everything is okay i think becouse by hand in db its works just there..
ericmp
ericmp•15mo ago
in the 1st message i sent, literally the 2 first words are "not sure", which i meant idk what is happening with ur code. then i just wanted u to notice that Brand::all()->pluck('name', 'id') could be optimised. that is why i showed u the benchmark thing, so u can see the difference. that is it.
gigiloouu
gigiloouuOP•15mo ago
aa thanks means second( ur way) is more fast? u mean that? idk i have form and model which i wrote
ericmp
ericmp•15mo ago
yes. and just in case u think it doesnt matter for couple ms, u can just add a bunch of records and do the benchmark again
gigiloouu
gigiloouuOP•15mo ago
and i have no idea why its not giving data
ericmp
ericmp•15mo ago
not sure what u mean have u set the relationships in the models?
gigiloouu
gigiloouuOP•15mo ago
yep i know that it does matte okay let me explane i have table
gigiloouu
gigiloouuOP•15mo ago
No description
gigiloouu
gigiloouuOP•15mo ago
like this and i have form also
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->minLength(2),
Select::make('brand_id')
->label('Brand')
->multiple()
->relationship('brand', 'name')
->searchable()
->required()
->options(Brand::all()->pluck('name', 'id'))
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
]),
Select::make('subbrand_id')
->label('Subbrand')
->multiple()
->relationship('subbrand', 'name')
->searchable()
->options(Subbrand::all()->pluck('name', 'id'))
->columnSpan('full')
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Subbrand'),
]),
]);
}
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->minLength(2),
Select::make('brand_id')
->label('Brand')
->multiple()
->relationship('brand', 'name')
->searchable()
->required()
->options(Brand::all()->pluck('name', 'id'))
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
]),
Select::make('subbrand_id')
->label('Subbrand')
->multiple()
->relationship('subbrand', 'name')
->searchable()
->options(Subbrand::all()->pluck('name', 'id'))
->columnSpan('full')
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Subbrand'),
]),
]);
}
this is my form where I save name brands and subbrands also
gigiloouu
gigiloouuOP•15mo ago
This is model of this form
No description
gigiloouu
gigiloouuOP•15mo ago
any ideas?
developer
developer•15mo ago
in your form schema Select::make('brand_id') you need to have only ONE of this: ->relationship() OR ->options() not both remove options()
gigiloouu
gigiloouuOP•15mo ago
okay i remove options() but its not working same error idk it was working yesterday d.. I remove relationshop now and its works.. hmm but when I click to edit
developer
developer•15mo ago
ok so the relationship is wrong
gigiloouu
gigiloouuOP•15mo ago
No description
gigiloouu
gigiloouuOP•15mo ago
now i have this eror.. yep and becouse of that I have error in edit
developer
developer•15mo ago
change the relationship from belongsTo to hasOne
gigiloouu
gigiloouuOP•15mo ago
same error..
developer
developer•15mo ago
No description
developer
developer•15mo ago
this error is self explanatory man you need to pass the value $name
gigiloouu
gigiloouuOP•15mo ago
yep sure i get it but how or where šŸ’€ i should do it in edit supplier? like this resource edit file ? yep i already did it
gigiloouu
gigiloouuOP•15mo ago
where? I named Attribute
developer
developer•15mo ago
in the supplier model
gigiloouu
gigiloouuOP•15mo ago
public function attribute(string $name): Attribute {
return Attribute::make(
get: fn($value) => explode(',', $value),
set: fn($value) => implode(',', $value),
);
}
public function attribute(string $name): Attribute {
return Attribute::make(
get: fn($value) => explode(',', $value),
set: fn($value) => implode(',', $value),
);
}
Its Attribute
developer
developer•15mo ago
not sure what you trying to do but try to use a different name also you expecting to pass a $name so...
gigiloouu
gigiloouuOP•15mo ago
idk it was working yesterday why its not working idk like im using this becouse of brands and subbrands which i give is many to many like its 1,2,3,4 string so to take data and set im using this to split
developer
developer•15mo ago
try to rename the attribute function i gotta go, you better use chatgpt to debug that shit šŸ˜† and its not a filament-related problem tbh
gigiloouu
gigiloouuOP•15mo ago
i try it but gpt is shit šŸ˜„ yep i think same becouse it was working yesterday.. i didnt remember should i use anything more like
public function brandId(): Attribute {
return $this->attribute('brandId');
}
public function brandId(): Attribute {
return $this->attribute('brandId');
}
I should use this brandId anywhere? šŸ’€ fixed thanks
ericmp
ericmp•15mo ago
what was the issue?
gigiloouu
gigiloouuOP•15mo ago
its not important to give $name attribute so i made this
public function attribute(): Attribute {
return Attribute::make(
get: fn($value) => explode(',', $value),
set: fn($value) => implode(',', $value),
);
}
public function brandId(): Attribute {
return $this->attribute();
}

public function subbrandId(): Attribute {
return $this->attribute();
}
public function attribute(): Attribute {
return Attribute::make(
get: fn($value) => explode(',', $value),
set: fn($value) => implode(',', $value),
);
}
public function brandId(): Attribute {
return $this->attribute();
}

public function subbrandId(): Attribute {
return $this->attribute();
}
I just remove names
ericmp
ericmp•15mo ago
hmm i dont understand this code u say u r doing it for what? -> https://discord.com/channels/883083792112300104/1214094864854290502/1214118779789905971
gigiloouu
gigiloouuOP•15mo ago
in db i have many ids in one column like 1,2,3,4 so for split it and parse im using this code its many to mnay
ericmp
ericmp•15mo ago
or i dont understand it or u r overcomplicating it. but yeah if works for u then its fine i guess
gigiloouu
gigiloouuOP•15mo ago
yep its works so who gives a fuck d btw thanks for ur best advice about that and ur time also ā¤ļø
ericmp
ericmp•15mo ago
šŸ™Œ (:

Did you find this page helpful?