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