php - Where Operator In Laravel -
i need use operator check ids in table following
$subscids = subjectschedule::where('subject_start_id',input::get('substid')) ->wherenull('deleted_at') ->select('id')->get(); $subscidsarray = array() ; foreach ($subscids $id) { $subscidsarray [] = $id->id ; } // here issue $subscinstudattends = studentattendees::wherein('subject_schedule_id',$subscidsarray) ->select('subject_schedule_id')->get(); if ($subscinstudattends) { return " true " . $subscinstudattends; }else{ return "false"; }
my issue in code
$subscinstudattends = studentattendees::wherein('subject_schedule_id',$subscidsarray) ->select('subject_schedule_id')->get();
wherein working fetch id in $subscidsarray
, need check each id of ids if one id in $subscidsarray
not equal subject_schedule_id
' return false ;
how can ? suggestions ?
you can check length of array contains ids against length of records returned.
if( count($subscidsarray) == count($subscinstudattends) ){ // ids in array have corresponding record in database }
or better, if application logic permits it, count of records , compare length of ids array.
$subscinstudattendscount = studentattendees::wherein('subject_schedule_id', $subscidsarray)->count('subject_schedule_id'); if( count($subscidsarray) == $subscinstudattendscount ){ // ids in array have corresponding record in database }
this code assumes ids in database unique.
Comments
Post a Comment