am tired from try and try pls help

so am work with a small project and am using Wizard form all is work perfect intil i use 3 table in the same page i have a 'client' table and cars table and matrucul table public static function form(Form $form): Form { return $form ->schema([ Wizard::make([ Wizard\Step::make('Order') ->description('Review your basket') ->schema([ Select::make('client_id') ->label('Client') ->relationship('client', 'name') ->searchable() ->preload() ->createOptionForm([ TextInput::make('name')->required(), TextInput::make('phone')->required(), ]) ->editOptionForm([ TextInput::make('name')->required(), TextInput::make('phone')->required(), ])
17 Replies
awcodes
awcodes2mo ago
Show us the code.
YASSIN459
YASSIN4592mo ago
->live() ->afterStateUpdated(function ($state, $set) { $client = Client::find($state); if ($client) { $firstCar = $client->cars()->first(); if ($firstCar) { $set('car_id', $firstCar->id); $carsRelated = $client->cars()->pluck('model', 'id')->toArray(); $otherCars = Car::whereNotIn('id', array_keys($carsRelated))->pluck('model', 'id')->toArray(); $carOptions = [ 'Related Cars' => $carsRelated, 'Other Cars' => $otherCars, ]; $set('car_options', $carOptions); $matricule = Matricule::where('client_id', $client->id) ->where('car_id', $firstCar->id) ->first(); if ($matricule) { $set('matricule_id', $matricule->id); $set('matricule', $matricule->mat); } else { $set('matricule_id', null); $set('matricule', ''); } } else { $set('car_id', null); $set('car_options', []); $set('matricule_id', null); $set('matricule', ''); } } else { $set('car_id', null); $set('car_options', []); $set('matricule_id', null); $set('matricule', ''); } Select::make('car_id') ->label('Car') ->searchable() ->options(function ($get) { return $get('car_options') ?: []; }) ->createOptionForm([ TextInput::make('model')->required(), ]) ->createOptionUsing(function ($data, $set, $get) { $car = Car::create($data); $clientId = $get('client_id'); if ($clientId) { $carsRelated = Car::where('client_id', $clientId)->pluck('model', 'id')->toArray(); $otherCars = Car::whereNotIn('id', array_keys($carsRelated))->pluck('model', 'id')->toArray(); $carOptions = [ 'Related Cars' => $carsRelated, 'Other Cars' => $otherCars, ]; $set('car_options', $carOptions); } return $car->id; }) ->live() ->afterStateUpdated(function ($state, $set, $get) { $clientId = $get('client_id'); if ($clientId && $state) { $matricule = Matricule::where('client_id', $clientId) ->where('car_id', $state) ->first(); if ($matricule) { $set('matricule_id', $matricule->id); $set('matricule', $matricule->mat); } else { $set('matricule_id', null); $set('matricule', ''); } } else { $set('matricule_id', null); $set('matricule', ''); } }), TextInput::make('matricule') ->label('Matricule') ->live() ->afterStateUpdated(function ($state, callable $set, $get) { $clientId = $get('client_id'); $carId = $get('car_id'); if (!$clientId || !$carId) { $set('matricule_id', null); return; } $set('matricule', $state); }), TextInput::make('matricule_id') ->label('Matricule ID'), ]), Wizard\Step::make('Delivery') ->schema([ TextInput::make('km')->required()->numeric(), TextInput::make('bl_number')->required(), TextInput::make('product')->required(), TextInput::make('price')->numeric(), ]), Wizard\Step::make('Billing') ->schema([ TextInput::make('qte') ->numeric(), TextInput::make('total') ->numeric(), // TextInput::make('remark') // ->maxLength(255), ]), ]) ]); am sorry the discord dont want for post all the code in one single time when i select the client it will show the car is related with and the matrucule this work but if the client dont have the matrucul i try to add it manualy , but because the matrucul table is another table the record is not validate
awcodes
awcodes2mo ago
Sounds like a relationship might be off somewhere. Could always share the full code in a gist too if you have a github account.
YASSIN459
YASSIN4592mo ago
i can opload the source code in git hub
awcodes
awcodes2mo ago
If it a public repo that would help too.
YASSIN459
YASSIN4592mo ago
in phpmyadmin it is work good
YASSIN459
YASSIN4592mo ago
GitHub
GitHub - yassin459dz/CAR-WORKSHOP
Contribute to yassin459dz/CAR-WORKSHOP development by creating an account on GitHub.
awcodes
awcodes2mo ago
Hang in there though. No doubt it can be frustrating. Looks like you’re doing some complicated logic. Where should we look in the repo?
YASSIN459
YASSIN4592mo ago
i dont want to make you tired for me sire
awcodes
awcodes2mo ago
If I can’t help someone else probably can. It’s ok. But we definitely can’t help without the code. So thanks for sharing it.
YASSIN459
YASSIN4592mo ago
thanq you sire this is the code https://github.com/yassin459dz/CAR-WORKSHOP
GitHub
GitHub - yassin459dz/CAR-WORKSHOP
Contribute to yassin459dz/CAR-WORKSHOP development by creating an account on GitHub.
YASSIN459
YASSIN4592mo ago
yeah it is a bit complicated but not so mush but i have another question
awcodes
awcodes2mo ago
Right, but what resource do we need to look at?
YASSIN459
YASSIN4592mo ago
ah the bl resource but i have another question how can i use filament frontend resource in separed project
awcodes
awcodes2mo ago
What do you mean by frontend resource. Resources are specific to panels. Looking at the code I think you are trying to do too much overriding and setting instead of utilizing the relationships on the model. To be honest though, I’m on my phone, but I’m wondering if a HasManyThrough might be more appropriate. I could be entirely wrong though.
YASSIN459
YASSIN4592mo ago
yeah discord is already show you are using phone , i want to use frontend resource in separet project without filament (i dont thinq is can be used) i thinq the problem is with the relationship i can try again
awcodes
awcodes2mo ago
Just let us know. The community here will help when they can.
Want results from more Discord servers?
Add your server