mardi 21 mars 2017

Not duplicate id of scholar resulte

Hi can anyone help me about my problem. i creating a criteria of my project, If the id is ['1','2'] it will search possible scholar that matched with the needs of scholarship. If the need_status of the scholar searched by the scholarship was "taken" it will not be included in the list.

ScholarshipNeed
id              scholarship_id      need_id
1                   2                   1
2                   2                   2

ScholarNeed
id              scholar_id              Need_id             need_status
1                   1                       1                   Available
1                   1                       2                   Available
1                   3                       1                   Available
1                   3                       2                   Taken
1                   4                       1                   Available

$scholarship_needs = ScholarshipNeed::where('scholarship_id','=',$scholarship_id)->get();            
$all_need_id = [];
foreach ($scholarship_needs as $id6) {
    array_push($all_need_id, $id6->need_id);
}
$scholar3 = array();
$scholarNeed = ScholarNeed::whereIN('scholar_id',$Scholar2)->whereIn('need_id',$all_need_id)->where('need_status','Available')->get();     
foreach ($scholarNeed as $all) {
    array_push($scholar3, $all->scholar_id);
}   

dd($scholar3);

This is the result right now

array:1 [▼
0 => 1
1 => 1
2 => 3
3 => 4
]

This is what i want to be result:

array:1 [▼
0 => 1
1 => 4
]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire