lundi 5 décembre 2016

Accessing data from one table which not belong to the other two table

//sample database

At first Scholar has 1,2,3,4,5,6 ids

Scholar      
Id      
1   
2
3
4
5
6

Now 1 and 2 were taken under table Member

Member 
Id
1 - taken
2 - taken

Next 3 and 4 were taken under table AddRequest

AddRequest
Id
3 - taken
4 - taken

now the Scholar table should only has the ids 5 and 6 which i want to display.

how can i resolve this problem using my code below

public function ListOrgaScholar($ship_id)
{
    $members = Member::where('ship_id','=',$ship_id)->get();
    $members = $members->toArray();
    $scholar_ids = array_pluck($members, 'scholar_id');
    $scholar_exits = Scholar::whereNotIn('scholar_id', $scholar_ids)->get();

    $requests = AddRequest::where('ship_id','=',$ship_id)->get();
    $requests = $requests->toArray();
    $scholar_ids = array_pluck($requests, 'scholar_id');
    $add_exits = Scholar::whereNotIn('scholar_id', $scholar_ids)->get();   

    if ($scholar_exits == true && $add_exits == true) {

    $scholars = (new Scholar)->newQuery()->select('*');

    $scholars = $scholars->get();
    dd($scholars);
}else{
}
}

result of dd

Collection {#302 ▼
  #items: array:7 [▼
    0 => Scholar {#305 ▶}
    1 => Scholar {#306 ▶}
    2 => Scholar {#307 ▶}
    3 => Scholar {#308 ▶}
    4 => Scholar {#309 ▶}
    5 => Scholar {#310 ▶}
    6 => Scholar {#311 ▶}
  ]
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2g1Yf1h
via IFTTT

Aucun commentaire:

Enregistrer un commentaire