F
Filamentā€¢4mo 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
gigiloouuā€¢4mo ago
any ideas?
ericmp
ericmpā€¢4mo 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
gigiloouuā€¢4mo 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ā€¢4mo ago
in tinker for example - php artisan tinker add \App\Models\ before the model name
gigiloouu
gigiloouuā€¢4mo ago
i should write it in model?
ericmp
ericmpā€¢4mo 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
gigiloouuā€¢4mo ago
okay and where i should writ eit ? aa in terminal?
ericmp
ericmpā€¢4mo ago
if u do php artisan tinker u can execute arbitrary code yes thats an option
gigiloouu
gigiloouuā€¢4mo ago
No description
gigiloouu
gigiloouuā€¢4mo ago
i got it what is it ? šŸ’€
ericmp
ericmpā€¢4mo ago
the benchmark results xd
gigiloouu
gigiloouuā€¢4mo 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
gigiloouuā€¢4mo ago
No description
gigiloouu
gigiloouuā€¢4mo 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ā€¢4mo 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
gigiloouuā€¢4mo ago
aa thanks means second( ur way) is more fast? u mean that? idk i have form and model which i wrote
ericmp
ericmpā€¢4mo 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
gigiloouuā€¢4mo ago
and i have no idea why its not giving data
ericmp
ericmpā€¢4mo ago
not sure what u mean have u set the relationships in the models?
gigiloouu
gigiloouuā€¢4mo ago
yep i know that it does matte okay let me explane i have table
gigiloouu
gigiloouuā€¢4mo ago
No description
gigiloouu
gigiloouuā€¢4mo 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
gigiloouuā€¢4mo ago
This is model of this form
No description
gigiloouu
gigiloouuā€¢4mo ago
any ideas?
developer
developerā€¢4mo 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
gigiloouuā€¢4mo 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ā€¢4mo ago
ok so the relationship is wrong
gigiloouu
gigiloouuā€¢4mo ago
No description
gigiloouu
gigiloouuā€¢4mo ago
now i have this eror.. yep and becouse of that I have error in edit
developer
developerā€¢4mo ago
change the relationship from belongsTo to hasOne
gigiloouu
gigiloouuā€¢4mo ago
same error..
developer
developerā€¢4mo ago
No description
developer
developerā€¢4mo ago
this error is self explanatory man you need to pass the value $name
gigiloouu
gigiloouuā€¢4mo 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
gigiloouuā€¢4mo ago
where? I named Attribute
developer
developerā€¢4mo ago
in the supplier model
gigiloouu
gigiloouuā€¢4mo 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ā€¢4mo ago
not sure what you trying to do but try to use a different name also you expecting to pass a $name so...
gigiloouu
gigiloouuā€¢4mo 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ā€¢4mo 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
gigiloouuā€¢4mo 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ā€¢4mo ago
what was the issue?
gigiloouu
gigiloouuā€¢4mo 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ā€¢4mo ago
hmm i dont understand this code u say u r doing it for what? -> https://discord.com/channels/883083792112300104/1214094864854290502/1214118779789905971
gigiloouu
gigiloouuā€¢4mo 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ā€¢4mo ago
or i dont understand it or u r overcomplicating it. but yeah if works for u then its fine i guess
gigiloouu
gigiloouuā€¢4mo ago
yep its works so who gives a fuck d btw thanks for ur best advice about that and ur time also ā¤ļø
ericmp
ericmpā€¢4mo ago
šŸ™Œ (: