[Bug]: The slug is not supported
Opened this issue · 1 comments
hagmir7 commented
What happened?
When we use a slug as keyName, it results in a TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given.
How to reproduce the bug
Please add a slug support
Package Version
2.0.4
PHP Version
8.2.18
Laravel Version
11.15
Which operating systems does with happen with?
No response
Notes
The package will be more useful if there is slug support as key name
jhoanborges commented
same error: array_search(): Argument #2 ($haystack) must be of type array, null given
I'm also using slug, which i think is the best for edit cases.
#4 seems like this is related to.
<?php
namespace App\Filament\Resources\SellerResource\Pages;
use App\Filament\Resources\SellerResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use JoseEspinal\RecordNavigation\Traits\HasRecordNavigation;
class EditSeller extends EditRecord
{
use HasRecordNavigation;
protected static string $resource = SellerResource::class;
protected function getHeaderActions(): array
{
$existingActions = [
Actions\DeleteAction::make(),
];
return array_merge($existingActions, $this->getNavigationActions());
}
protected function beforeValidate(): void
{
//dd($this->data);
}
protected function afterSave()
{
$user = $this->record;
$this->syncSkills($user);
$this->syncAntiSkills($user);
/*$skills = $this->data['normal_skills'] ?? [];
$skillsWithPivot = [];
foreach ($skills as $skillId) {
$skillsWithPivot[$skillId] = ['type' => 'normal'];
}
$this->record->normalSkills()->sync($skillsWithPivot);
$anti_skills = $this->data['anti_skills'] ?? [];
$skillsAntiWithPivot = [];
foreach ($anti_skills as $skillId) {
$skillsAntiWithPivot[$skillId] = ['type' => 'anti'];
}
$this->record->antiSkills()->sync($skillsAntiWithPivot);*/
}
protected function syncSkills($user)
{
$skills = $this->data['normal_skills'] ?? [];
$skillsWithPivot = [];
foreach ($skills as $skillId) {
$skillsWithPivot[$skillId] = ['type' => 'normal'];
}
$user->normalSkills()->sync($skillsWithPivot);
}
protected function syncAntiSkills($user)
{
$anti_skills = $this->data['anti_skills'] ?? [];
$skillsAntiWithPivot = [];
foreach ($anti_skills as $skillId) {
$skillsAntiWithPivot[$skillId] = ['type' => 'anti'];
}
$user->antiSkills()->sync($skillsAntiWithPivot);
}
}