Research of null value in relation (belongs to many)

Hi✋ I have a list of users(personnes) who have a location. personnel table : id ,id_corp,.... lieu_affectation_histories: id , personnel_id,lieu_affectation_id,... lieu_affectaion : id , name_fr,name_ar,.... Model Personnel :
public function lieuAffectation()
{
return $this->belongsToMany(LieuAffectation::class, LieuAffectationHitories::class);
}
public function lieuAffectation()
{
return $this->belongsToMany(LieuAffectation::class, LieuAffectationHitories::class);
}
Personnel Ressource :
Tables\Filters\SelectFilter::make('id')
->relationship('lastLieuAffectation', 'name_fr')
->multiple()
->label("Lieu d'affectaion")
->options(
LieuAffectation::all()->pluck('name_fr', 'id')->toArray()
// LieuAffectation::all()->pluck('name_fr', 'id')->prepand('null','')->toArray()

),
Tables\Filters\SelectFilter::make('id')
->relationship('lastLieuAffectation', 'name_fr')
->multiple()
->label("Lieu d'affectaion")
->options(
LieuAffectation::all()->pluck('name_fr', 'id')->toArray()
// LieuAffectation::all()->pluck('name_fr', 'id')->prepand('null','')->toArray()

),
**What I'm looking for, is a search of all personnel who don't have a location. Thanks.
4 Replies
Dennis Koch
Dennis Koch2y ago
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
ROOT-LEE
ROOT-LEEOP2y ago
Yes the "querying-relationship-existence" was the key word
$data = Personnel::query()->has('lieuAffectation')->get()->toArray()
$data = Personnel::query()->has('lieuAffectation')->get()->toArray()
This request gives me everyone who doesn't have a location. ------- It is possible to add in a selective filter an option with 'person without having a location' that call the previus query ?
location_1 location_2 location_3 personne_without_locattion
Tables\Filters\SelectFilter::make('id')
->relationship('lastLieuAffectation', 'name_fr')
->multiple()
->label("Lieu d'affectaion")
->options(
LieuAffectation::all()->pluck('name_fr', 'id')->toArray()
),
Tables\Filters\SelectFilter::make('id')
->relationship('lastLieuAffectation', 'name_fr')
->multiple()
->label("Lieu d'affectaion")
->options(
LieuAffectation::all()->pluck('name_fr', 'id')->toArray()
),
Dennis Koch
Dennis Koch2y ago
Use a filter form with a checkbox/toggle or similar
ROOT-LEE
ROOT-LEEOP2y ago
All right, thanks for that suggestion.. 😎
Want results from more Discord servers?
Add your server